note 130251 added to reflectionproperty.getdeclaringclass
| From: | kp42@ya.ru | Date: | Wed, 16 Apr 2025 11:16:39 +0000 |
| Subject: | note 130251 added to reflectionproperty.getdeclaringclass | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-222090@lists.php.net to get a copy of this message | ||
Be careful when use getDeclaringClass() for properties from traits
<?php
trait Y {
public $y;
}
class X {
use Y;
}
$x = new X();
$x->y = 42;
$reflection = new ReflectionObject($x);
echo $reflection->getProperty('y')->getDeclaringClass()->getName(); // X
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 109.71.244.180)
----
Manual Page -- https://php.net/manual/en/reflectionproperty.getdeclaringclass.php
Edit -- https://main.php.net/note/edit/130251
Del: integrated -- https://main.php.net/note/delete/130251/integrated
Del: useless -- https://main.php.net/note/delete/130251/useless
Del: bad code -- https://main.php.net/note/delete/130251/bad+code
Del: spam -- https://main.php.net/note/delete/130251/spam
Del: non-english -- https://main.php.net/note/delete/130251/non-english
Del: in docs -- https://main.php.net/note/delete/130251/in+docs
Del: other reasons-- https://main.php.net/note/delete/130251
Reject -- https://main.php.net/note/reject/130251
Search -- https://main.php.net/manage/user-notes.php