php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71157 Using reserved words in magic methods
Submitted: 2015-12-18 11:21 UTC Modified: 2015-12-18 14:00 UTC
Votes:2
Avg. Score:2.5 ± 1.5
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sergey dot karavay at gmail dot com Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 5.5.30 OS: Windows 7 x64
Private report: No CVE-ID: None
 [2015-12-18 11:21 UTC] sergey dot karavay at gmail dot com
Description:
------------
Define __call and __callStatic methods for a class. Then try to call both static and non-static methods as a reserved keyword (for example, list).

Test script:
---------------
<?php
class Testing {

    public function scopeList() {
        echo "scopeList";
    }

    public function __call($method, $parameters) {
        if($method == "list") {
            $this->scopeList();
        }
    }

    public static function __callStatic($method, $parameters) {
	echo 1; die();
        $instance = new static;
        call_user_func_array([$instance, $method], $parameters);
    }
}

Testing::list(); // fails
Testing::{'list'}(); // works

$testing = new Testing();
$testing->list(); //works

Expected result:
----------------
The same behavior for both (both fails or both works).

Actual result:
--------------
Fails for static call, works for non-static.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-18 13:45 UTC] gregorv at web dot de
You shouldn't just copy some stuff, but give reference to the original poster...
 [2015-12-18 13:57 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2015-12-18 13:57 UTC] nikic@php.net
Supported in PHP 7.
 [2015-12-18 13:58 UTC] sergey dot karavay at gmail dot com
-Status: Closed +Status: Open
 [2015-12-18 13:58 UTC] sergey dot karavay at gmail dot com
To gregorv at web dot de

Yep, sorry, was too initiative. 
The issue was originally posted on: http://stackoverflow.com/questions/34353400/php-using-language-constructs-in-combination-with-magic-methods
 [2015-12-18 14:00 UTC] sergey dot karavay at gmail dot com
-Status: Open +Status: Closed
 [2015-12-18 14:00 UTC] sergey dot karavay at gmail dot com
Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 14:01:32 2024 UTC