colap Posted June 25, 2011 Share Posted June 25, 2011 function &getInstance($boot = true) { static $instance = array(); if (!$instance) { if (!class_exists('Set')) { require LIBS . 'set.php'; } $instance[0] =& new Configure(); $instance[0]->__loadBootstrap($boot); } return $instance[0]; } Why is & there? function &getInstance And is it php4 syntax using the & ?$instance[0] =& new Configure(); Quote Link to comment https://forums.phpfreaks.com/topic/240397-question-with-php-function/ Share on other sites More sharing options...
Cagecrawler Posted June 25, 2011 Share Posted June 25, 2011 & before a function name means the function returns a reference. The second & is to do with references as well, it passes a reference of the Configure object to $instance[0], rather than a copy. Quote Link to comment https://forums.phpfreaks.com/topic/240397-question-with-php-function/#findComment-1234811 Share on other sites More sharing options...
colap Posted June 26, 2011 Author Share Posted June 26, 2011 The second &, obj=& new classname();. Is that php-4 syntax? Quote Link to comment https://forums.phpfreaks.com/topic/240397-question-with-php-function/#findComment-1234865 Share on other sites More sharing options...
Cagecrawler Posted June 26, 2011 Share Posted June 26, 2011 I think so, the manual talks of a change to the errors thrown in PHP4.4.0. Quote Link to comment https://forums.phpfreaks.com/topic/240397-question-with-php-function/#findComment-1234875 Share on other sites More sharing options...
KevinM1 Posted June 26, 2011 Share Posted June 26, 2011 The second &, obj=& new classname();. Is that php-4 syntax? Yes. In PHP 5 objects are automatically passed by reference. Quote Link to comment https://forums.phpfreaks.com/topic/240397-question-with-php-function/#findComment-1234909 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.