Hi Mike,

Missed your e-mail because it went to the list only.

What you're demonstrating here is functionally equivalent to the simple
example I provided. (The example was intended to show how this feature
works, not necessarily how you would use it in practice.)

The key difference, is that a native reference carries no contextual
information with it - a form-helper for instance can't determine which
object the referenced property belongs to, the name of the property, or
even the fact that the variable is referencing an object-property in the
first place.

You also can't use the & operator to create a reference to a virtual
(__get/__set) property, because you would be creating a reference to the
value that is returned by the __get() method, rather than to a (virtual)
property of an object.

That's why form-helpers currently store references to objects, and
reference properties using strings - rather than using native
variable-references as in your example.

---

From: "Ford, Mike" <m.f...@leedsmet.ac.uk>
To: PHP internals <internals@lists.php.net>
Cc:
Date: Wed, 1 May 2013 13:20:32 +0000
Subject: RE: [PHP-DEV] property de-referencing
I know I'm still somewhat of a beginner with OOP, and not at all into
large-scale OOP frameworks (yet!), but I'm really struggling to understand
why the existing & reference operator doesn't suffice for what you are
after?

If you could explain in words of as few syllables as possible what you
would want to add to:

   class User
   {
       public $name;
   }

   $user = new User;
   $user->name = 'Rasmus';

   $nameprop = &$user->name;

   var_dump($nameprop); // => 'Rasmus'

   $nameprop = 'Bob';

   var_dump($nameprop); // => 'Bob'


I would be immensely grateful, as I might then stand a chance of deciding
whether I'm with you or agin you...!


Cheers!

Mike

Reply via email to