php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63954 Parser should recognize objects within parenthesis
Submitted: 2013-01-10 01:22 UTC Modified: 2014-10-12 15:12 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: php at kfee-programming dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.20 OS: Debian GNU/Linux 6.0
Private report: No CVE-ID: None
 [2013-01-10 01:22 UTC] php at kfee-programming dot com
Description:
------------
Placing any object within parentheses and attempting to access members of that 
object causes the parser to fail with an error. This makes chaining difficult, 
particularly with clones. 
One would expect that parenthesis should have no effect 
on the identity of the variable or expression they are surrounding, but this 
failure of the parser causes a change in identity to not-an-object.

This was reported as a bug #30533, but was declared NAB with no additional 
reasoning. This is thus a change request.

Test script:
---------------
<?php
$Now = new \DateTime();
$OneSecAgo = (clone $Now)->sub(new \DateInterval("PT1S"));
//Or $OneSecAgo = clone($Now)->sub(new \DateInterval("PT1S"));
//Neither work.
echo $Now->format("c") , "\n" , $OneSecAgo->format("c");

Expected result:
----------------
2013-01-09T17:01:35-08:00
2013-01-09T17:01:34-08:00

Actual result:
--------------
[Wed Jan 09 17:01:35 2013] [error] [client *.*.*.*] PHP Parse error:  syntax 
error, unexpected T_OBJECT_OPERATOR in /var/www/test.php on line 3


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-10 02:40 UTC] aharvey@php.net
There are probably two separate issues here: (clone $foo)->bar() should probably work since (new $foo)->bar() does, then there's the bigger issue of objects being treated more consistently as the result of parenthesised expressions.
 [2013-01-10 02:40 UTC] aharvey@php.net
-Package: Compile Failure +Package: Scripting Engine problem
 [2014-10-12 15:12 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2014-10-12 15:12 UTC] nikic@php.net
Supported in PHP 7.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 10:01:32 2024 UTC