php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52591 possibility of calling protected static methods in not inherited classes
Submitted: 2010-08-12 12:52 UTC Modified: 2010-08-12 13:53 UTC
From: v dot kholoshenko at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.14 OS: any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: v dot kholoshenko at gmail dot com
New email:
PHP Version: OS:

 

 [2010-08-12 12:52 UTC] v dot kholoshenko at gmail dot com
Description:
------------
PHP allows to call protected static method in classes not inherited from class, 
that defines this method. See test script. We have two classes inherited from 
basic abstract class and we can call protected functions (defined abstract) of 
first class from second. Note, call_user_func caused error (works as expected).

Test script:
---------------
<?php
abstract class A {
	abstract protected static function test();
}

class B extends A {
	protected static function test()
	{
		return "abc";
	}
}

abstract class C extends A {
	public static function do1()
	{
		return B::test();// Expected "Fatal error: Call to protected method..."
	}
}

echo C::do1(); // returns 'abc'

Expected result:
----------------
Fatal error: Call to protected method B::test() from context 'C'

Actual result:
--------------
abc

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-12 13:34 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-08-12 13:34 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

That is exactly what protected means.
 [2010-08-12 13:53 UTC] v dot kholoshenko at gmail dot com
ok, so why call_user_func doesn't works in such way?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 22:01:34 2025 UTC