From: sven dot arduwie at gmail dot com
Operating system: win xp pro sp3
PHP version: 5.3.0RC1
PHP Bug Type: Reflection related
Bug description: hasProperty inconsistent with getProperty and new
ReflectionProperty
Description:
------------
In the reproduce code hasProperty() in Base::__get() returns true while
getProperty() throws an exception with message "Fatal error: Uncaught
exception 'ReflectionException' with message 'Property test does not
exist'"
A more appropriate message would be "Fatal error: Uncaught exception
'ReflectionException' with message 'Cannot access non-public member
Child::test'", OR, and perhaps this would be best, change the behavior of
hasProperty() to return false.
The current behavior is really annoying if you're, like me, trying to
write a __get() method that returns the value of private/protected
properties using 'getters', e.g.: getMyProperty() for property $myProperty.
Reproduce code:
---------------
<?php
class Base {
public function __get($property) {
$reflector = new ReflectionObject($this);
if ($reflector->hasProperty($property)) {
return $reflector->getProperty($property)->getValue();
}
}
}
class Child extends Base {
private $test = 'This is a test.';
}
class Test extends Child {
}
$test = new Test;
var_dump($test->test);
Expected result:
----------------
getProperty() to throw "Fatal error: Uncaught exception
'ReflectionException' with message 'Cannot access non-public member
Child::test'"
or
hasProperty() to return false
Actual result:
--------------
hasProperty() returns true while getProperty() throws a message with an
inappropriate message
--
Edit bug report at http://bugs.php.net/?id=47808&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=47808&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=47808&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=47808&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=47808&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=47808&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=47808&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=47808&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=47808&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=47808&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=47808&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=47808&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=47808&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=47808&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=47808&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47808&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47808&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=47808&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=47808&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=47808&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=47808&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=47808&r=mysqlcfg