CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

function &get_instance(){}

Open HakureiMarisa opened this issue 11 years ago • 4 comments

return CI_Controller::get_instance(); or return &CI_Controller::get_instance();

HakureiMarisa avatar Sep 14 '15 02:09 HakureiMarisa

Or at least try to be clear.

narfbg avatar Sep 14 '15 08:09 narfbg

As the doc described at http://www.codeigniter.com/user_guide/general/creating_libraries.html 1

However, in my opinion, to reference the original CodeIgniter object, the function get_instance should be defined as

return &CI_Controller::get_instance();

instead of

return CI_Controller::get_instance();

And, I notice that in CI3.0 it doesn't use & as it declared, e.g. in line 69 , system/database/DB.php

foreach (get_instance()->load->get_package_paths() as $path)

I'm really ashamed with my poor English, I hope I have described my question clearly. Thanks!

HakureiMarisa avatar Sep 14 '15 09:09 HakureiMarisa

If you tried to declare a function that way, you'd see that this would be a syntax error: https://3v4l.org/eLAu4

Please don't ask such questions here ... it's a bug tracker, not a forum board. And if you want to improve something, test and verify it first.

narfbg avatar Sep 14 '15 09:09 narfbg

ah, I see. And thank you for your guidance.

HakureiMarisa avatar Sep 14 '15 09:09 HakureiMarisa