Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:24948 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25261 invoked by uid 1010); 24 Jul 2006 19:25:42 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 25221 invoked from network); 24 Jul 2006 19:25:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jul 2006 19:25:41 -0000 X-Host-Fingerprint: 83.160.219.156 korving.demon.nl Received: from ([83.160.219.156:16569] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.3 r(11751M)) with ESMTP id C5/C7-04178-30A15C44 for ; Mon, 24 Jul 2006 15:05:39 -0400 Message-ID: To: internals@lists.php.net References: <44C4ECC6.8080401@kaluma.com> <200607241916.27024.johannes@php.net> <1153763607.30382.184.camel@notebook.local> Date: Mon, 24 Jul 2006 21:05:16 +0200 Lines: 72 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Posted-By: 83.160.219.156 Subject: Re: [PHP-DEV] Pass by reference (5.1.1 vs 5.1.2) From: r.korving@xit.nl ("Ron Korving") Actually Todd, ... > There is no way to call a function > before doing the work in the argument list. If I call f(1+2), > I can be sure the computation to get 3 will be performed > _before_ calling f. The issue with f($p=array()) is that > "$p=array()" is an r-value. ...that is theoretically very possible, and it's something called "lazy evaluation": http://en.wikipedia.org/wiki/Lazy_evaluation - Ron "Todd Ruth" wrote in message news:1153763607.30382.184.camel@notebook.local... > It looks like > http://www.php.net/manual/en/language.operators.assignment.php > could use a bit of updating. A paragraph about php 5 or a > link to the semantics changes for php 5 would help newbies. > The text about php4 says there is copy on assignment, which > implies a performance hit for using = instead of =&, but I > believe "copy on change" is more accurate. It wouldn't hurt > to explicitly say that "=" is generally better than "=&" > (unless you really need an alias). A user comment has been > there unchallenged for over 2 years saying you can pass an > assignment as a reference to a function, so it isn't surprising > that someone considered the 5.1.1 to 5.1.2 change an issue. > (Not that a user comment should bind the php devs, but when > the comment goes unchallenged, it can lead to false impressions.) > Perhaps some text explaining the assignment returns an r-value > would be helpful. (If people understand "($x = 1) = 2;" > shouldn't work, they might understand that passing "$x=1" to > a function by reference shouldn't affect $x. (or should > "($x = 1) = 2;" work and 5.1.2 had a real bug?)) > > I have to say the documentation for php is completely awesome > and is a major factor in our company using the language. I > just point out the above to help; it isn't a complaint. > > BTW, I disagree with the post below that indicates the issue is > the order of calling. There is no way to call a function > before doing the work in the argument list. If I call f(1+2), > I can be sure the computation to get 3 will be performed > _before_ calling f. The issue with f($p=array()) is that > "$p=array()" is an r-value. > > - Todd > > On Mon, 2006-07-24 at 19:16 +0200, Johannes Schlueter wrote: > > Hi, > > > > On Monday 24 July 2006 17:52, Rishad Omar wrote: > > > getArray($p = array()); > > > > Here you are relying on undefined behavior. It is not defined wether $p = > > array() or the function call getarray($p) should be executed first so the > > order might always change. > > > > You should always use the two lines > > $p = array(); > > getArray($p); > > to be safe. > > > > johannes > > > -- > Todd Ruth