Edit report at https://bugs.php.net/bug.php?id=63463&edit=1
ID: 63463
User updated by: ocramius at gmail dot com
Reported by: ocramius at gmail dot com
Summary: ReflectionProperty::setValue and ::getValue trigger
magic methods
-Status: Feedback
+Status: Open
Type: Bug
Package: Reflection related
Operating System: Irrelevant
PHP Version: 5.4.8
Block user comment: N
Private report: N
New Comment:
@stas let me put it into a more "practical" use case I currently have:
I use reflection to populate instances of proxy objects that have "lazy" marked
properties unset at instantiation time. This is good to achieve lazy loading of
public properties, but any r/w access to the property itself via reflection
triggers `__get` or `__set`.
This makes it impossible to use reflection to populate the property. I worked
around it by disabling `__get` in particular situations (see
https://github.com/Ocramius/common/blob/DCOM-96/lib/Doctrine/Common/Reflection/RuntimePublicReflectionProperty.php),
but at a terrible cost in performance terms and broken behaviour in rare cases.
Back to the issue itself:
I consider Reflection as my last resource to access and modify status of
objects without affecting anything else within my environment. Having
reflection trigger any logic during an assignment is an unwanted and dangerous
behaviour in my opinion.
Previous Comments:
------------------------------------------------------------------------
[2012-12-10 01:51:32] [email protected]
I'm not sure why you think this is what should be happening. When you unset
properties, they are no longer set. And when you access unset properties, magic
methods kick in. So where's the problem here?
------------------------------------------------------------------------
[2012-11-08 06:22:43] ocramius at gmail dot com
I've added the failing test case as a PR at
https://github.com/php/php-src/pull/230
------------------------------------------------------------------------
[2012-11-08 06:15:03] ocramius at gmail dot com
Description:
------------
When unset properties are requested, ReflectionProperty::setValue and
ReflectionProperty::getValue trigger __get and __set magic methods.
Test script:
---------------
https://gist.github.com/4037155
Expected result:
----------------
The test script should report NULL for each of the requested values, and never
call __set nor __get
Actual result:
--------------
__set and __get are called when ReflectionProperty tries to read or write to
the requested properties.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63463&edit=1