php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77740 called static direct from brother class
Submitted: 2019-03-14 02:40 UTC Modified: 2019-03-14 02:47 UTC
From: neder dot fandino at outlook dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 7.3.3 OS: Centos 7.0
Private report: No CVE-ID: None
 [2019-03-14 02:40 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-14 02:47 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-03-14 02:47 UTC] requinix@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC