From:
Operating system: ANY
PHP version: 5.3.3
Package: Scripting Engine problem
Bug Type: Bug
Bug description:( new Class() ) -> method() throws a PHP parse error
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 bug report at http://bugs.php.net/bug.php?id=53378&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=53378&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=53378&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=53378&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=53378&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=53378&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=53378&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=53378&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=53378&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=53378&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=53378&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=53378&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=53378&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=53378&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=53378&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53378&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53378&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=53378&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=53378&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=53378&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=53378&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=53378&r=mysqlcfg