3

So it seems that inside a method of this class we have a case where when the __callStatic should be called, the __call is used instead for some reason.

<?php

class Test {

    public function __call($name, $params){
        echo "__call()";
    }
    
    public static function __callStatic($name, $params){
        echo "__callStatic()";
    }
    
    public function wtf(){
        Test::nonExistingStaticMethod();
    }

}

$test = new Test();
$test->wtf(); // expected: __callStatic , actually: __call

this comes a bit unexpectedly and annoyingly, but there's probably an explanation?

br4nnigan
  • 646
  • 6
  • 13
  • https://www.php.net/manual/en/language.oop5.overloading.php#object.callstatic - callStatic is when `Test` is called statically. `Test::wtf()` – aynber Nov 17 '22 at 18:49
  • 1
    but the type of call of the nonExistingStaticMethod function itself should be relevant, which clearly is called statically, not how the function where the call happens was called. I mean If I call AnotherTestClass::nonExistingStaticMethod, then the call does indeed happen statically. – br4nnigan Nov 17 '22 at 18:56
  • Per the docs, `__call() is triggered when invoking inaccessible methods in an object context., __callStatic() is triggered when invoking inaccessible methods in a static context.`. That is talking about how the class is invoked, not the method. – aynber Nov 17 '22 at 18:56
  • 2
    The problem might also be that you consider `::` to be only for static methods, but this is not true which [this](https://3v4l.org/d5iuW) shows and [this](https://stackoverflow.com/a/3173511/231316) answer explains – Chris Haas Nov 18 '22 at 04:07
  • @ChrisHaas yes ok, but using `forward_static_call_array(['Test', 'nonExistingStaticMethod'], []);` instead of :: gives the same result – br4nnigan Nov 21 '22 at 09:43
  • That example gives a static call as expected, unless I'm not understanding? https://3v4l.org/bL63C – Chris Haas Nov 21 '22 at 14:12

0 Answers0