Edit report at http://bugs.php.net/bug.php?id=53378&edit=1
ID: 53378 Updated by: [email protected] Reported by: marco dot weber at uni-trier dot de Summary: ( new Class() ) -> method() throws a PHP parse error -Status: Open +Status: Duplicate Type: Feature/Change Request Package: Scripting Engine problem Operating System: ANY PHP Version: 5.3.3 Block user comment: N Private report: N New Comment: Duplicate of numerous other requests, the oldest I can find being request #34502. Patches welcome, I suspect. Previous Comments: ------------------------------------------------------------------------ [2010-11-22 13:41:14] marco dot weber at uni-trier dot de Description: ------------ In Java or C# it is allowed to do ( new Class() ) -> method() calls, why not in PHP? This is very useful for more complex commands, f.e.: $collection = new QueryableCollection($employees); $collection->setAsName('c1'); $collection->where(new OrCondition( new ColumnEquals( ( new Column('c1.job') ) ->subString(0, 5)->toLower(), 'admin'), new AndCondition( new ColumnBiggerThan('c1.age', 10), new ColumnLowerThan('c1.age', 20), ) )) ->sortByDesc( ( new Column('c1.job') ) ->toLower()) ->sortByAsc('c1.nachname') ->sortByAsc('c1.vorname') ->select('c1.*'); Test script: --------------- <?php class MyString { protected $string=''; public function __construct($string) { if(is_string($string)) $this->string=$string; } public function length() { return strlen($this->string); } } echo("This string has a length of: " . (new MyString('teststring'))->length() ."\n"); /* instead you have to do it like that :( $ms=new MyString('teststring'); echo("This string has a length of: " . $ms->length() ."\n"); */ ?> Expected result: ---------------- PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR in ... Actual result: -------------- No Syntax error. PHP should just create the object and execute its Method. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53378&edit=1
