Bug #70791 [NEW]: Inconsistent method_exists() property_exists() behavior.

From: Date: Mon, 26 Oct 2015 13:28:20 +0000
Subject: Bug #70791 [NEW]: Inconsistent method_exists() property_exists() behavior.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196814@lists.php.net to get a copy of this message
From:             phplists at stanvassilev dot com
Operating system: OSX
PHP version:      7.0.0RC5
Package:          *General Issues
Bug Type:         Bug
Bug description:Inconsistent method_exists() property_exists() behavior.

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.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=70791&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=70791&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=70791&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=70791&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=70791&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=70791&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=70791&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=70791&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=70791&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=70791&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=70791&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=70791&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=70791&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=70791&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70791&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=70791&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=70791&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=70791&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70791&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=70791&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=70791&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#196814) next »