|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-10-30 15:43 UTC] reeze@php.net
-Status: Open
+Status: Not a bug
[2015-10-30 15:43 UTC] reeze@php.net
[2015-10-31 13:53 UTC] phplists at stanvassilev dot com
[2019-09-03 12:04 UTC] nikic@php.net
-Status: Not a bug
+Status: Closed
-Assigned To:
+Assigned To: nikic
[2019-09-03 12:04 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 01:00:01 2025 UTC |
Description: ------------ The rules under which a class member is reported to "exist" for method_exists() property_exists() are inconsistent. property_exists will look into all members visible from inside a given class, be it private, public or protected, but it won't report *parent class private properties* as existing for that class. method_exists will report a parent class private method as existing for the child class, but the child class has no access to it internally. This is not a new problem in PHP7, but it's an issue in general. I believe the property_exists() behavior is correct, and method_exists() causes unexpected results. Test script: --------------- class BobSenior { private $a; protected $b; private function a() {} protected function b() {} } class BobJunior extends BobSenior { private $c; protected $d; private function c() {} protected function d() {} } $senior = new BobSenior(); $junior = new BobJunior(); var_dump(property_exists($senior, 'a')); // bool(true) -> EXPECTED var_dump(method_exists($senior, 'a')); // bool(true) -> EXPECTED var_dump(property_exists($senior, 'b')); // bool(true) -> EXPECTED var_dump(method_exists($senior, 'b')); // bool(true) -> EXPECTED var_dump(property_exists($senior, 'c')); // bool(false) -> EXPECTED var_dump(method_exists($senior, 'c')); // bool(false) -> EXPECTED var_dump(property_exists($senior, 'd')); // bool(false) -> EXPECTED var_dump(method_exists($senior, 'd')); // bool(false) -> EXPECTED var_dump(property_exists($junior, 'a')); // bool(false) -> EXPECTED var_dump(method_exists($junior, 'a')); // bool(true) -> *NOT* EXPECTED (EXPECTED = false) var_dump(property_exists($junior, 'b')); // bool(true) -> EXPECTED var_dump(method_exists($junior, 'b')); // bool(true) -> EXPECTED var_dump(property_exists($junior, 'c')); // bool(true) -> EXPECTED var_dump(method_exists($junior, 'c')); // bool(true) -> EXPECTED var_dump(property_exists($junior, 'd')); // bool(true) -> EXPECTED var_dump(method_exists($junior, 'd')); // bool(true) -> EXPECTED Expected result: ---------------- Please check comments for expected results. Actual result: -------------- Please check comments for actual results.