php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55247 Parser problem with static calls using string method name
Submitted: 2011-07-20 05:55 UTC Modified: 2011-08-01 12:10 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: gehrig at teqneers dot de Assigned: dmitry (profile)
Status: Closed Package: *General Issues
PHP Version: 5.3.6 OS: Darwin 10.8.0
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gehrig at teqneers dot de
New email:
PHP Version: OS:

 

 [2011-07-20 05:55 UTC] gehrig at teqneers dot de
Description:
------------
PHP allows to call instance methods using the {} syntax together with a string - 
such as $obj->{'my-method'} for example. This allows developers to call methods 
whose names are not valid PHP method names.

The same does not work with static method calls. 

Test script:
---------------
<?php
class Test{
    public static function __callStatic($method, $arguments)
	{
        echo $method . PHP_EOL;
    }
    public function __call($method, $arguments) 
	{
        echo $method . PHP_EOL;
    }
}

$method = 'method';

$test = new Test();

$test->method();
$test->$method();
$test->{'method'}();

Test::method();
Test::$method();
Test::{'method'}();


Expected result:
----------------
method
method
method
method
method
method

Actual result:
--------------
PHP Parse error:  syntax error, unexpected '{', expecting T_STRING or T_VARIABLE 
or '$' in Untitled.php on line 21

Patches

55247.diff (last revision 2011-07-27 04:46 UTC by pierrick@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-22 18:53 UTC] felipe@php.net
-Type: Bug +Type: Feature/Change Request
 [2011-07-22 18:53 UTC] felipe@php.net
It isn't supposed to work, so not a bug.

Changed to feature request.
 [2011-07-27 04:46 UTC] pierrick@php.net
The following patch has been added/updated:

Patch Name: 55247.diff
Revision:   1311742018
URL:        https://bugs.php.net/patch-display.php?bug=55247&patch=55247.diff&revision=1311742018
 [2011-08-01 11:46 UTC] dmitry@php.net
-Assigned To: +Assigned To: dmitry
 [2011-08-01 12:10 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 [2011-08-01 12:10 UTC] dmitry@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Apr 29 18:01:28 2025 UTC