There is the following code:

class A { public $value = 100; } $property = &(new A)->value; /// Это не работает 

How to be? Separately write strings like this:

 $obj = new A; $property = &obj->value; 

Do not offer!

PS I expect an answer in the style: None

  • Actually, what are you trying to achieve in this way $property = &(new A)->value ? You can refer to the field of the created instance .... well, either a static ..... it is logical that everything is meaningless without creating an instance and subsequent reference to it - Alexey Shimansky
  • But after all there are records ala: $property = &$obj_of_A->value; and everything works fine, in addition, you can not use the assignment by reference, that is, $property = (new A)->value; and the same will work fine, your comment about this is incomprehensible to me! - MaximPro
  • one
    What exactly will work normally with $property = (new A)->value ? you copy the value of the object field and that's it. then that object will die on the next lines, the GC will be removed and you will work with a copy of the value of that same class field. no links will be there ........... $property = &$obj_of_A->value; it works because a copy of the class has already been created and it will live happily and happily referring to the address in memory until you kill it .... therefore, the assignment of the link takes place here ....... because there is something to manipulate .. - Alexey Shimansky
  • one
    $property = &(new A)->value; here you are trying to take a link to the field of an object that was not even created. roughly speaking no addresses were allocated and you want to refer to it ..... refer to the abyss ...... I can not even imagine where you can refer to that way)) As I already wrote: the option when the field will exist if it static, i.e. not tied to the object - Alexey Shimansky
  • Okay, I understand you! - MaximPro

0