php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50810 property_exists does not work for private
Submitted: 2010-01-20 21:09 UTC Modified: 2010-03-07 01:49 UTC
Votes:2
Avg. Score:2.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: gaboto at gmail dot com Assigned: felipe
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3, 6 OS: *
Private report: No CVE-ID:
 [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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-20 23:17 UTC] gaboto at gmail dot com
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());
?>
 [2010-01-21 03:31 UTC] gaboto at gmail dot com
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)
 [2010-01-21 10:06 UTC] jani@php.net
Using class name instead of object shows the expected result. I'd guess (according to docs) it should be same in both ways though.
 [2010-03-07 01:49 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=295910
Log: - Fixed bug #50810 (property_exists does not work for private)
 [2010-03-07 01:49 UTC] felipe@php.net
-Status: Verified +Status: Closed
 [2010-03-07 01:49 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 21:01:56 2014 UTC