|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-12-03 13:44 UTC] robin_fernandes at uk dot ibm dot com
Description: ------------ get_class_methods() should list accessible private and protected methods if it is called from class scope (this is not stated explicitly in the doc, but is mentioned in Dmitry's comment to bug 32296). However, the testcase below shows a situation where, at a given scope, a method is accessible yet not listed by get_class_methods(). Specifically, this occurs with protected methods accessed from a superclass scope. Reproduced on php53 and php6 snaps on Windows. Reproduce code: --------------- <?php class C { public static function test() { D::prot(); var_dump(get_class_methods("D")); } } class D extends C { protected static function prot() { echo "Successfully called D::prot().\n"; } } C::test(); ?> Expected result: ---------------- Successfully called D::prot(). array(2) { [0]=> string(4) "prot" [1]=> string(4) "test" } Actual result: -------------- Successfully called D::prot(). array(1) { [0]=> string(4) "test" } PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 13:00:02 2025 UTC |
The standard get_method handler (which is used to retrieve a method before executing it) uses zend_check_protected() to verify whether a protected method is accessible. zend_check_protected() returns true if the current scope is the same as, a child of OR a parent of the protected method's declaring class. However, get_class_methods() implements its own algorithm to filter out non visible methods. This algorithm excludes protected methods unless the current scope is an "instance of" the method's declaring class (so it is more restrictive than zend_check_protected()): [...] if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC) || (EG(scope) && (((mptr->common.fn_flags & ZEND_ACC_PROTECTED) && instanceof_function(EG(scope), mptr->common.scope TSRMLS_CC)) || ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) && EG(scope) == mptr->common.scope)))) { [...]