From: rainmaker at omenmedia dot com
Operating system: Windows 2000
PHP version: 4.3.1
PHP Bug Type: Feature/Change Request
Bug description: Limitations of deprecating call time pass by reference
Firstly, I'll apologise in advance if this issue has been raised before,
but I think I have a valid point here, please hear me out...
When testing some code on another server the other day, I was presented
with quite a few errors relating to call time pass by reference. I have
never seen these errors when developing locally as the server I use has
allow_call_time_pass_reference set to on (as part of the dist PHP ini).
Going through my code I found the problems it was referring to: a couple
of occasions where I was passing in a value by reference into a function,
where the function definition did not explicitly specify the argument to
be passed by reference. I went about correcting this, however discovered
some limitations with function definition references and the current PHP
engine.
These limitations relate primarily to the fact that you cannot specify a
default value for a reference argument in a function definition, thereby
making the argument *required* and non-optional. This is a huge issue.
For example, I have a class called StringWriter which takes one argument
(a string) through the constructor. Now, this argument is *supposed* to
be optional, however it also could be (and indeed often is) a reference to
a string somewhere else. If I recode this class to satisfy the deprecated
call time reference passing requirements, more problems are created:
With call time references, this is all fine:
$writer = new StringWriter();
$writer = new StringWriter("string");
$writer = new StringWriter($aString);
$writer = new StringWriter(&$anotherString);
However without them:
$writer = new StringWriter(); // ERROR, argument required
$writer = new StringWriter("string"); // Fine
$writer = new StringWriter($aString); // Fine
$writer = new StringWriter(&$anotherString); // ERROR (obviously)
In this case, where the argument could equally be a reference or a
non-reference, the user is forced to create the object like this:
$writer = new StringWriter("");
...to avoid an error, which is a PITA if you ask me. Surely the fact that
we are now 'forced' to code without using call time references, and yet
cannot under any circumstances specify that a reference argument is
optional (with a default value) is a huge limitation?
And also, doesn't it make *more* sense to allow the developer to decide
whether they want to pass a value or a reference? I'm not sure of the
technical issues (i.e. zend engine) surrounding call time passed
references, but to me, unless function definition reference arguments can
be made optional, call time passed references just seem to make a whole
lot more sense.
Because some of my code under the current circumstances *requires* call
time passed references, I'm pretty much forced to inform anybody who uses
my code that they must modify their ini to allow them... not good. Please
don't "bogus" this report because I feel this is a huge issue that need to
be addressed.
Thanks.
--
Edit bug report at http://bugs.php.net/?id=22833&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=22833&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=22833&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=22833&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=22833&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=22833&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=22833&r=support
Expected behavior: http://bugs.php.net/fix.php?id=22833&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=22833&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=22833&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=22833&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22833&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=22833&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=22833&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=22833&r=gnused