Re: Passing-by-reference

From: Date: Thu, 23 Nov 2000 20:47:23 +0000
Subject: Re: Passing-by-reference
References: 1  Groups: php.dev php.qa 
Request: Send a blank email to php-dev+get-39033@lists.php.net to get a copy of this message
At 03:11 PM 11/23/00 -0500, Ignacio Vazquez-Abrams wrote:
On Thu, 23 Nov 2000, Andi Gutmans wrote: a) Do you prefer to document the three ways which work foo($a), foo(bar()) where bar() is defined as function which returns a reference, and foo(new testclass) and all the rest will be documented as undefined. b) Do you want to define the "undefined" behavior in some way, i.e., always create a copy of the returned data and pass it. Thanks, Andi --- Andi Gutmans <andi@zend.com> http://www.zend.com/ c) Throw an error. More than likely this will indicate a coding problem, and just passing a copy will cause a developer to scratch her head and say "WTF?" for several months while trying to figure out the problem(s). Leaving behavior as undefined will just cause memory corruption problems for sloppy developers, which is what we want to get away from in the first place.
Throwing an error is a problem because we can't really detect it. With my patch the undefined behavior will not cause memory corruption anymore but will either throw an error or continue working (i.e. undefined). In the manual it would say something like: Receiving arguments by reference: ---------------------------------------- Three ways of passing an argument to a function which wants to receive its argument by reference: a) foo($a) // Passing a variable b) foo(new foo()) // Passing a newly created object c) foo(MyFactory()) // Where MyFactory() is explicitly defined to return the return value by reference, which is done by defining it as "function &MyFactor(){...}" ALL OTHER ARGUMENT PASSING RESULTS IN UNDEFINED BEHAVIOR! How's that? :) Andi Andi --- Andi Gutmans <andi@zend.com> http://www.zend.com/

« previous php.dev (#39033) next »