Bug #78372 [Nab]: Calling __set magic method on ReflectionProperty::setValue()
Edit report at https://bugs.php.net/bug.php?id=78372&edit=1
ID: 78372
Updated by: nikic@php.net
Reported by: i dot spyric at gmail dot com
Summary: Calling __set magic method on
ReflectionProperty::setValue()
Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Debian
PHP Version: 7.4.0beta1
Block user comment: N
Private report: N
New Comment:
While this is technically "expected", I do think that we may need to do something about
this, though I'm not sure what. See also bug #78226.
Previous Comments:
------------------------------------------------------------------------
[2019-08-05 07:20:45] requinix@php.net
The RFC states that __get will be invoked upon reading an uninitialized typed property. Logically,
__set should be invoked when writing an uninitialized typed property.
This behavior matches how an unset() untyped property works, even when using reflection. https://3v4l.org/Gs1XL
------------------------------------------------------------------------
[2019-08-05 07:10:32] i dot spyric at gmail dot com
Description:
------------
When you use setting value via reflection on uninitialized property __set magic method will be
called.
If you remove type of property or set default value, __set method will not be called.
Is it a bug? Because in RFC I have not seen anything about this behavior
Test script:
---------------
class Example {
private string $test;
public function __set($name, $value)
{
echo "$name=$value";
}
}
$t = new Example();
$property = new ReflectionProperty($t, 'test');
$property->setAccessible(true);
$property->setValue($t, 'foo');
Expected result:
----------------
No __set is called
Actual result:
--------------
__set is called
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78372&edit=1
Thread (5 messages)