php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77344 Why is it judged to use __call
Submitted: 2018-12-25 01:12 UTC Modified: 2018-12-25 03:47 UTC
From: hongweichen8888 at sina dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.2.13 OS: All
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: hongweichen8888 at sina dot com
New email:
PHP Version: OS:

 

 [2018-12-25 01:12 UTC] hongweichen8888 at sina dot com
Description:
------------
When using the __call and __callStatic functionality on a parent class calls to A::method() will use __call rather than the __callStatic. 

Test script:
---------------
class A {
    function __call($name, $arguments) {
        echo "non-static\n";
    }

    static function __callStatic($name, $arguments){
        echo "static\n";
    }
}

class B extends A {
    function fun() {
        parent::test(); // with calling scope
        A::test();      // ?
    }
}

$obj = new B();
$obj->fun();

Expected result:
----------------
non-static
static

Actual result:
--------------
non-static
non-static

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-25 01:33 UTC] Wes dot example at example dot org
if $this is set, __call is called, otherwise __callStatic
that regardless of what's on the left of the :: operator

using parent:: or A:: is the same from php's perspective in this case

I know it's a bit odd. Perhaps php should have a different way to resolve the parent class than the static method syntax
 [2018-12-25 01:42 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-12-25 01:42 UTC] requinix@php.net
:: is the scope resolution operator. It is not the "static method call" operator. In fact there is no such thing as a static method call operator.
 [2018-12-25 02:46 UTC] hongweichen8888 at sina dot com
class C {       // without extends
    function fun() {
        A::test();
    }
}
$obj2 = new C();
$obj2->fun();
// output: static

In this case, is $this not set?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 21:01:35 2025 UTC