Brion Vibber wrote:
Rasmus Lerdorf wrote:
PHP 5.0 broke this.  There was a fatal error on the array_shift that
only variables could be passed by reference.  There was a good
argument for it.  So, we started migrating our code.

Well, seems this works in 5.1.  So, my question is, was it an
intentional "fix" or will this break again and we need to continue to
watch for this?
In 5.1 this now throws an E_STRICT instead of a warning.  It is still a
bad idea to pass a tempvar by reference, so yes, you should strive to
write E_STRICT clean code.

Stupid question: why is it a bad idea?

Well, the original reason was because it caused weird and wonderful memory corruption in PHP 4.3.x, so if your code is ever going to run on that version you really need to not do that.

It also tends to be a bug. Most functions that take an argument by reference do so for a reason. There are of course exceptions to this as you have pointed out and in those cases assuming your code will never run under PHP 4.3.x it can be valid. I would still say it is a better idea to something like:

  func_taking_reference($quiet=some_func());  // throw away ref mod

and document the fact that you are intentionally throwing away the reference modification that func_taking_reference is making. That way you avoid the E_STRICT and make it very clear what you are doing.

You could make the same argument for using undefined variables. Often that indicates a bug so the E_NOTICE can be really helpful, but other times it just gets in the way. I don't think that means we should do away with the E_NOTICE on that and I also don't think it means you shouldn't try to write E_NOTICE clean code.

-Rasmus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to