Re: Allow (...)->foo() expressions not only for `new`

From: Date: Tue, 26 Feb 2013 16:49:08 +0000
Subject: Re: Allow (...)->foo() expressions not only for `new`
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-66250@lists.php.net to get a copy of this message
On Tue, Feb 26, 2013 at 7:41 AM, Dmitry Stogov <dmitry@zend.com> wrote: > Hi Nikita, > > I like the idea. > But note, that it may cause some unexpected behaviour and bugs. > I didn't test the patch I just guess it on my previous experience > introducing similar features. > > - usage expression in write context (e.g. passing constant by reference) > > function foo(&$foo) {} > foo("abc"[0]); > > - destruction of temporary result > > ($a . $b)[4]; // if ($a.$b) is destroyed? > > - in some cases destruction of temporary result may cause destruction of > final result > > ((object)(array("a"=>"b")))->a = "c"; // temporary object > may be destroyed > before assignment > > All these edge cases must be carefully analyzed. > I like the current patch, and in case the edge cases won't require many > hacks, I'm all for it. > > Thanks. Dmitry. > I just played a bit with it and came up with the following (additional) patch to support use in write context: https://github.com/nikic/php-src/commit/31705dd8c53efe3bb52d6aae483a324e5a511ae9It throws an error if the write is done on a TMP or CONST, but things like (new foo)->bar = 'x' will work. Though I'm not quite sure whether this is really necessary, at least I don't see much use for it. Reading your mail again, I missed the second point (about destruction of temporary). But I wonder how it could cause any issue. I mean, FREE op is only inserted when expression is used as statement, which is not the case here. Or am I missing something? Nikita

« previous php.internals (#66250) next »