php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #45772 ReflectionProperty::setValue/getValue how are "by reference" calls done?
Submitted: 2008-08-09 23:11 UTC Modified: 2009-11-20 14:10 UTC
From: jtaal at eljakim dot nl Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jtaal at eljakim dot nl
New email:
PHP Version: OS:

 

 [2008-08-09 23:11 UTC] jtaal at eljakim dot nl
Description:
------------
From the documentation it is unclear:

What happens when I want to assign a property by reference using ReflectionProperty::setValue.
Also unclear what happens with ReflectionProperty::getValue.

Maybe this should also be a Feature Request, requesting additional methods that set a reference / return a reference.

In my opinion it is not necessary to create a special getValueByRef method, only the setValueByRef is necessary (getValue could always return by ref because you still need the other & for it to work).

Reproduce code:
---------------
class MyClass {
  public $myProperty;
}
$obj = new MyClass;
$globalProp = 'value1';
$refl = new ReflectionObject($obj);
$reflProp = $refl->getProperty('myProperty');
$reflProp->setValue($obj, $globalProp);

$globalProp = 'value2';

// what will the next line print: value1 or value2 => not clear from the documentation
echo $obj->myProperty; // prints value1
//------
class MyClass {
  public $myProperty = 'value1';
}
$obj = new MyClass;
$refl = new ReflectionObject($obj);
$reflProp = $refl->getProperty('myProperty');
$globalProp = & $reflProp->getValue($obj);

$globalProp = 'value2';

// what will the next line print: value1 or value2 => unclear according to docs
echo $obj->myProperty; // print value1 & E_STRICT is raised






Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-20 14:10 UTC] vrana@php.net
getValue and setValue clearly states that it takes the value, not the reference.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Mon Jun 15 04:00:01 2026 UTC