ballhogjoni Posted October 7, 2010 Share Posted October 7, 2010 I am getting an error saying Deprecated: Assigning the return value of new by reference is deprecated in /Users/xxx/dev/git/xxxx/cake/libs/inflector.php on line 131 I understand that this is because =& has been deprecated in php 5.3+, the question i have is what do I do about it? are the objects passed as references still or do I handle them some other way? My server is running 5.2.5 and my dev machine is running 5.3.2. Does this error act like a fatal error and break out of the script or does it act more like a notice? Sorry for all the questions, just been out of php since php 4, don't know all the changes. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/215372-what-to-do-about-idiom/ Share on other sites More sharing options...
rwwd Posted October 7, 2010 Share Posted October 7, 2010 can you post that line of code so that we can see the context of the error please Is this after you sorted out the ini file error at all? ;p Rw Quote Link to comment https://forums.phpfreaks.com/topic/215372-what-to-do-about-idiom/#findComment-1119982 Share on other sites More sharing options...
ballhogjoni Posted October 7, 2010 Author Share Posted October 7, 2010 yes i sorted out the ini file. here is the function: function &getInstance() { static $instance = array(); if (!$instance) { $instance[0] =& new Inflector(); if (file_exists(CONFIGS.'inflections.php')) { include(CONFIGS.'inflections.php'); $instance[0]->__pluralRules = $pluralRules; $instance[0]->__uninflectedPlural = $uninflectedPlural; $instance[0]->__irregularPlural = $irregularPlural; $instance[0]->__singularRules = $singularRules; $instance[0]->__uninflectedSingular = $uninflectedPlural; $instance[0]->__irregularSingular = array_flip($irregularPlural); } } return $instance[0]; } These deprecated messages are coming from cakePHP's framework...so I guess they haven't updated yet. Quote Link to comment https://forums.phpfreaks.com/topic/215372-what-to-do-about-idiom/#findComment-1119985 Share on other sites More sharing options...
rwwd Posted October 7, 2010 Share Posted October 7, 2010 Mmm, that's new one on me ;p The manual states this:- Note that the assignment copies the original variable to the new one (assignment by value), so changes to one will not affect the other. This may also have relevance if you need to copy something like a large array inside a tight loop. Assignment by reference is also supported, using the $var = &$othervar; syntax. 'Assignment by reference' means that both variables end up pointing at the same data, and nothing is copied anywhere. To learn more about references, please read References explained. As of PHP 5, objects are assigned by reference unless explicitly told otherwise with the new clone keyword. Taken from this page so I guess that =& means to copy (PLEASE IF I AM WRONG ANYONE TELL ME!!!!) I actually thought it was similar to $$ (variable variable) which I try not to use so much. Hope that helps a little, I haven't seen this sort of code in the wild before.. Then again, I do bespoke. Then again, it's way past my bedtime, and I may have looked up the wrong type of operator, just sort through the options on the left hand menu until something looks familiar. Rw Quote Link to comment https://forums.phpfreaks.com/topic/215372-what-to-do-about-idiom/#findComment-1119986 Share on other sites More sharing options...
Alex Posted October 7, 2010 Share Posted October 7, 2010 It's not really a =& operator. It's a normal assignment operator (=) and a reference operator (&). I find it's confusing, and somewhat misleading, to write it like that, and I prefer to have it written this way: $var = &$somethingelse; In the code you posted, that usage was seen commonly in PHP 4 to circumvent issues caused by flaws in the poor OOP support. It is no longer necessary because as of PHP 5 all objects are, by default, passed by reference. Quote Link to comment https://forums.phpfreaks.com/topic/215372-what-to-do-about-idiom/#findComment-1119992 Share on other sites More sharing options...
ballhogjoni Posted October 7, 2010 Author Share Posted October 7, 2010 like i said this is CakePHP's framework code...so don't blame me for it Quote Link to comment https://forums.phpfreaks.com/topic/215372-what-to-do-about-idiom/#findComment-1119997 Share on other sites More sharing options...
rwwd Posted October 7, 2010 Share Posted October 7, 2010 ^^^ Lol, nobody is blaming anyone, this is called learning.. No one is to blame when your learning.. @AlexWD: So at least I found the right page in the manual! It's actually pretty confusing as the manual has it like this and then there is the warning about using the reference operator within function & classes - but in essence the manual says that =& is correct, so I guess as it is a matter of your coding preferences. Well, they say you learn something new every day! Rw Quote Link to comment https://forums.phpfreaks.com/topic/215372-what-to-do-about-idiom/#findComment-1119998 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.