|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-01-20 21:09 UTC] gaboto at gmail dot com
Description:
------------
property_exists does not work for private property defined in a superclass.
Reproduce code:
---------------
<?php
class ExampleSuperclass
{
private $foo;
}
class ExampleSubclass extends ExampleSuperclass
{
function methodExists()
{
return method_exists($this, 'foo');
}
}
$example = new ExampleSubclass();
var_dump($example->methodExists());
?>
Expected result:
----------------
it must print bool(true)
Actual result:
--------------
it prints bool(false)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 22 08:00:01 2025 UTC |
I'm sorry, the example was wrong, this is the right example: <?php class ExampleSuperclass { private $foo; function propertyExists() { return property_exists($this, 'foo'); } } class ExampleSubclass extends ExampleSuperclass { } $example = new ExampleSubclass(); var_dump($example->propertyExists()); ?>Another more complete example here: <?php class ExampleSuperClass { private $foo; static protected $bar; private function foo() { } public function propertyFooExists() { return property_exists($this, 'foo'); } } class ExampleSubClass extends ExampleSuperClass { public function methodExists() { return method_exists($this, 'foo'); } public function propertyBarExists() { return property_exists($this, 'bar'); } } $example = new ExampleSubClass(); var_dump($example->methodExists()); var_dump($example->propertyFooExists()); var_dump($example->propertyBarExists()); ?> In php 5.2.1 you get: bool(true) bool(true) bool(false) php bool 5.3: bool(true) bool(false) bool(true) expected result: bool(true) bool(true) bool(true)