Nikita, your examples convinced me that a strict "accessor methods as 
specialized __get/__set semantics" approach is undesirable.

To recapitulate your two examples:

Example 1:

class A {
  public $foo;
}
class B extends A {
  public $foo { get() { ...} }
}

Example 2:

class A {
  public $foo { get() { ...} }
}
class B extends A {
  public $foo;
}

One would expect that in both cases, instances of 'class B' would have a $foo 
acting as declared in class B, shadowing the declaration from class A.

I think that the issue might be solved by an additional, not-yet-discussed and 
very general extension, which is something I missed being able to do from time 
to time: the possibility to declare a method (or property) in some class to be 
explicitly NOT inherited. Syntactically, something like

class C {
  public $bar;
  public function twiddle();
}
class D extends C {
  no public $bar;
  no public function twiddle();
 # might be followed by a different twiddle(), or $bar, implementation
}

The use case I have in mind, coming from the method side, is a subclass that 
wants to use __call() for delegation AND needs to delegate to one or more 
methods that are ordinarily plainly implemented in the base class.

What this feature would bring to the current discussion, is this possible 
solution to your dilemma:

1) when a class declares a plain property "public $foo", automatically apply
"no function __getfoo(); no function setfoo();" (leaving out isset/unset for 
clarity)
2) conversely, when a class declares "public $foo { get() {...}}", or even 
just declares one of the magic methods directly like "public function 
__getfoo() {}" - automatically prepend / pretend a "no public $foo;" 
cancelling a superclass property.

best regards
  Patrick


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

Reply via email to