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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
20 - 12 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 05:01:23 2020 UTC