Re: Feature request

From: Date: Tue, 21 Nov 2006 02:38:40 +0000
Subject: Re: Feature request
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-26692@lists.php.net to get a copy of this message
Richard Lynch wrote:
On Thu, November 9, 2006 11:48 pm, Stanislav Malyshev wrote:
There are some cases where this could start becoming quite challenging and we might get into reference counting/separation problems, i.e.: function foo() { return array(1,2,3); } foo()[1] = 4;
I'd say expression(f()[1]) means $tmp = f(); expression($tmp); unset($tmp); which here means: $tmp = foo(); $tmp[1] = 4; unset($tmp); which is meaningless but should work. IIRC the engine can make free's at the end of expression, so it shouldn't be big problem. Actually, any assignment to it if it's not returned by-ref is meaningless, but syntactically ok.
Last I checked, if foo() returned a string, the $tmp code above would alter the string contents... I rarely do this, but that's what I would expect it to do... But is it altering the original string, or a copy of the string or ??? You could make a ruling that this nifty new syntax is "read only" on the data, and you can't assign to it, but that's not what this naive reader would expect if this ()[] syntax is going to be supported.
Please pardon me for butting in here, but I am having a hard time understanding this thread. I like the idea of f()[1] meaning return the [1] element of an array or character returned by f(). f(){1} should also return a character from a string. On the other hand, foo()[1] = 4; is a syntax error, plain and simple. The way I see it functions RETURN values. You can't assign to a function, so why should you be able to assign to an element of it? What am I missing?

« previous php.internals (#26692) next »