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?

I would expect these to be equivalent for all intents and purposes:

  func_taking_reference(some_func());

and

  $temp = some_func();
  func_taking_reference($temp);

where $temp is never used again and quickly passes out of scope.

Is there some reason that they are not considered equivalent, or that they
cannot or should not be made equivalent?

I seem to remember a reason being quoted for all these reference-related changes
something like it can cause memory corruption. But that would appear to be an
implementation bug, not an essential difficulty, as if it were really *memory
corruption* I can't imagine it being turned back on in 5.1. :)

-- brion vibber (brion @ pobox.com / brion @ wikimedia.org)

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to