|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-11-16 04:11 UTC] daniel at ciochiu dot ro
[2018-12-26 16:16 UTC] jhdxr@php.net
-Status: Open
+Status: Not a bug
[2018-12-26 16:16 UTC] jhdxr@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 18:00:01 2025 UTC |
Description: ------------ According to the documentation, __callStatic() is triggered when invoking inaccessible methods in a static context. If a method then is declared non-static with a __callStatic() handler in the class, accessing the method statically should route through __callStatic() instead of generating a fatal error as the method is inaccessible statically. Test script: --------------- <?php class Test { protected $root = ''; public function __construct(string $root = '/') { $this->root = $root; } public static function bindTo(string $root = '/') { return new static($root); } public static function __callStatic($name, $arguments) { $instance = static::bindTo(); return $instance->$name($arguments); } public function test() { return $this->root . '/foo'; } } print Test::bindTo('/elsewhere')->test(); print Test::test(); Expected result: ---------------- /elsewhere/foo /foo Actual result: -------------- /elsewhere/foo PHP Fatal error: Uncaught Error: Non-static method Test::test() cannot be called statically