|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53378 ( new Class() ) -> method() throws a PHP parse error
Submitted: 2010-11-22 13:41 UTC Modified: 2010-11-23 10:32 UTC
From: marco dot weber at uni-trier dot de Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5.3.3 OS: ANY
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
31 - 17 = ?
Subscribe to this entry?

 [2010-11-22 13:41 UTC] marco dot weber at uni-trier dot de
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->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())

Test script:

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-22 16:41 UTC]
-Type: Bug +Type: Feature/Change Request
 [2010-11-23 10:32 UTC]
-Status: Open +Status: Duplicate
 [2010-11-23 10:32 UTC]
Duplicate of numerous other requests, the oldest I can find being 
request #34502. Patches welcome, I suspect.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 14 11:01:28 2024 UTC