Bug #77740 [Opn->Nab]: called static direct from brother class
| From: | requinix@php.net | Date: | Thu, 14 Mar 2019 02:47:59 +0000 |
| Subject: | Bug #77740 [Opn->Nab]: called static direct from brother class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219955@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77740&edit=1
ID: 77740
Updated by: requinix@php.net
Reported by: neder dot fandino at outlook dot com
Summary: called static direct from brother class
-Status: Open
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Centos 7.0
PHP Version: 7.3.3
Block user comment: N
Private report: N
New Comment:
methodProctected is defined in Father and MinorChild extends Father. That means MinorChild
"knows" about methodProctected, and can call it on other objects that extend Father.
Previous Comments:
------------------------------------------------------------------------
[2019-03-14 02:40:48] neder dot fandino at outlook dot com
Description:
------------
When calling a dynamically protected method from a sibling class, the current class does not use the
magic method __callStatic
Test script:
---------------
<?php
class Father {
protected function methodProctected() {
return __FUNCTION__;
}
public static function __callStatic($name, $arguments) {
$self = new static;
return call_user_func_array([$self, $name], $arguments);
}
}
var_dump(Father::methodProctected()); // print: string(16) "methodProctected"
class MajorChild extends Father {}
var_dump(MajorChild::methodProctected()); // print: string(16) "methodProctected"
class MinorChild extends Father {
public static function methodPublic() {
return MajorChild::methodProctected();
}
}
var_dump(MinorChild::methodPublic()); // print: WARNING Non-static method Father::methodProctected()
should not be called statically on line number 26 string(16) "methodProctected"
Expected result:
----------------
should execute the method inherited from the father through the magical method __callStatic
Actual result:
--------------
WARNING The non-static method should not be called statically
(try to execute the method as yourself)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77740&edit=1