ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-dev
php-dev
Re: [PHP-DEV] allow_call_time_pass_reference
by Todd Ruth other posts by this author
May 8 2008 2:44PM messages near this date
Re: [PHP-DEV] allow_call_time_pass_reference | Re: [PHP-DEV] allow_call_time_pass_reference
On Thu, 2008-05-08 at 22:58 +0200, Hannes Magnusson wrote:
>  On Thu, May 8, 2008 at 10:08 PM, Todd Ruth <truth@[...].com> 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
Thread:
Steph Fox
Hector Santos
Steph Fox
Steph Fox
Steph Fox
Hector Santos
Hannes Magnusson
Todd Ruth
Hannes Magnusson
Todd Ruth
Steph Fox
Steph Fox
Stanislav Malyshev

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved