On 1/3/13 5:43 PM, Stas Malyshev wrote:
The whole problem here is that the only reason why it is a problem is
because of the accessors that have hidden state in guards. If it were
regular variables (and for all the API consumer knows, they are) there

Please ignore this if it's been debated before:

AFAICT C# strictly separates fields ("properties" in PHP) and properties (a set of accessors that emulate a field).

So the RFC provides 3 features (using C# terms):
1. A property API
2. A built-in storage variable so you don't need a separate field
3. Access to the storage variable as if it were a field of the same name

I think #2 is useful, avoiding the need to make a separate field just to make properties read-only or type-hinted. However I think the complexity and confusion we're running into is mostly caused by #3.

I think we might be better served by having another way to access this storage 
variable.

What if instead, we have the storage var available as $prop inside all the accessors? These would be the default implementations:

  get         { return $prop; }
  set($value) { $prop = $value; }
  isset       { return $prop !== NULL; }
  unset       { $prop = NULL; }

Pros:
* Makes clear that $prop is regular var access, and that $this->PropertyName *always* goes through accessors * Gives isset/unset full access to the storage var, which allows doing things that can't be done via setter/getter. E.g. you could actually implement a property being "unset", which would be different from having it set to NULL.

Cons:
* Allows "evil", like having reads affect the storage var.
* Allows authors to hang themselves with recursive accessor calls, BUT those mistakes would be apparent from looking at the code.

What functionality possible in the RFC would be lost by this?

Steve Clay
--
http://www.mrclay.org/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to