#34502 [Opn->Bgs]: method chaining on constructor causes parse error

From: Date: Wed, 14 Sep 2005 21:25:35 +0000
Subject: #34502 [Opn->Bgs]: method chaining on constructor causes parse error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-85054@lists.php.net to get a copy of this message
ID: 34502 Updated by: johannes@php.net Reported By: goat at daholygoat dot com -Status: Open +Status: Bogus Bug Type: Feature/Change Request Operating System: Linux PHP Version: 5.0.5 New Comment: By reading the code I'd expect that A is some function returning an object. returnStr() being a method of that object returning a class name used for new. (Somehow a combination of "new $a;" and a simple "function_call()->methodCallOnReturnedObject()" which is possible since PHP 5) I would like some syntax like this, too - but thinking about it I see too much confusion and didn't find a nice solution which is clear when reading code. I set this to bogus since I think it's too much confusion, but if you have a nice and clear syntax feel free to re-open it - I'd be happy, but don't see how this is possible without logic conflicts :-) Previous Comments: ------------------------------------------------------------------------ [2005-09-14 21:26:50] derick@php.net I think this is simply not supported right now, so marking as a Feature Request ------------------------------------------------------------------------ [2005-09-14 21:14:57] goat at daholygoat dot com Description: ------------ When doing method chaining on a constructor (without seperately instantiating the object first), a parse error occurs. Reproduce code: --------------- class A { private $str; function A($str) { $this->str = $str; } function returnStr() { return $str; } } echo new A("hello")->returnStr(); Expected result: ---------------- The reference to an object of A created with A's constructor would allow me to call returnStr() on it. Actual result: -------------- I'm getting a parse error. PHP Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=34502&edit=1

« previous php.bugs (#85054) next »