On Thu, 2008-05-08 at 22:58 +0200, Hannes Magnusson wrote:
> On Thu, May 8, 2008 at 10:08 PM, Todd Ruth <[EMAIL PROTECTED]> wrote:
> > On Thu, 2008-05-08 at 20:28 +0100, Steph Fox wrote:
> >> ...
> >> Does anyone have a good reason for keeping it switched on by default in PHP
> >> 5.3? Like, would switching it off by default break a lot of existing code,
> >> given that most users are a bit beyond PHP 3 now?
> >
> > Well, I can at least comment on how it is used in the code that
> > I inherited.  First it must be noted that the following throws
> > a fatal error:
> >
> > function f(&$x=5) { ....
> 
> No it doesn't.
> That line does however not work exactly as you would expect..

Quite right.  I should have said "leads to fatal errors".
It doesn't throw a fatal error on it's own, but if you have old 
code that you must maintain in which a function is sometimes called
as f(), sometimes called as f(10), and sometimes called as f(&$y), 
trying to "fix it" with the declaration above will lead to fatal
errors for the f(10) calls.  (The defaulting part isn't the 
problem for that case; it's using a non-variable when a reference
is needed that leads to the fatal error.)

BTW, in php4, there was an incentive to use call-time
pass-by-reference.  Calling f(g()) was a very bad thing if
f always accepted its parameter by reference.  There are a number
of other similar cases.  In php5 (and the last few releases of
php4), it's still bad, but at least memory doesn't get 
corrupted now.  In contrast, not declaring f to accept its
parameter by reference and instead using call-time
pass-by-reference was (and is) safe (though deprecated).

- Todd


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

Reply via email to