|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-11-22 16:41 UTC] cataphract@php.net
-Type: Bug
+Type: Feature/Change Request
[2010-11-23 10:32 UTC] aharvey@php.net
-Status: Open
+Status: Duplicate
[2010-11-23 10:32 UTC] aharvey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 14:00:01 2025 UTC |
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.