note 94038 added to reflectionclass.hasproperty
| From: | rwilczek at web-appz dot de | Date: | Tue, 13 Oct 2009 12:40:20 +0000 |
| Subject: | note 94038 added to reflectionclass.hasproperty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161675@lists.php.net to get a copy of this message | ||
Note, that this method does not guarantee, that you can get a property with
ReflectionClass::getProperty().
ReflectionClass::hasProperty() considers the parent classes (ignoring however, that a private
property is not inherited), while ReflectionClass::getProperty() and
ReflectionClass::getProperties() don't care about inheritance.
(Tested with PHP 5.3.0)
<?php
class Foo
{
private $x;
}
class Bar extends Foo
{
//
}
$foo = new ReflectionClass('Foo');
$bar = new ReflectionClass('Bar');
var_dump($foo->hasProperty('x'); // bool(true)
var_dump($bar->hasProperty('x'); // bool(true)
var_dump(get_class($foo->getProperty('x'))); //string(18)
"ReflectionProperty"
try {
$bar->getProperty('x');
} catch (ReflectionException $e) {
echo $e->getMessage(); // Property x does not exist
}
?>
----
Server IP: 217.160.72.57
Probable Submitter: 80.153.202.193
----
Manual Page -- http://www.php.net/manual/en/reflectionclass.hasproperty.php
Edit -- https://master.php.net/note/edit/94038
Del: integrated -- https://master.php.net/note/delete/94038/integrated
Del: useless -- https://master.php.net/note/delete/94038/useless
Del: bad code -- https://master.php.net/note/delete/94038/bad+code
Del: spam -- https://master.php.net/note/delete/94038/spam
Del: non-english -- https://master.php.net/note/delete/94038/non-english
Del: in docs -- https://master.php.net/note/delete/94038/in+docs
Del: other reasons-- https://master.php.net/note/delete/94038
Reject -- https://master.php.net/note/reject/94038
Search -- https://master.php.net/manage/user-notes.php