Re: Class Properties in Interfaces?
| From: | Lars Strojny | Date: | Wed, 30 Apr 2008 19:14:04 +0000 |
| Subject: | Re: Class Properties in Interfaces? | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-37383@lists.php.net to get a copy of this message | ||
Good evening Stas,
Am Mittwoch, den 30.04.2008, 10:02 -0700 schrieb Stanislav Malyshev:
[...]
> You can easily do this by having __get call getProperty. That's like 1
> line of code to do. No language change needed.
With the substantial difference, that __get()/__set() does not work
properly with inheritance, as the language can't verify the LSP.
class Mother
{
public function __set($property, $value)
{
switch ($property) {
case 'foo':
$this->_foo = (string)$value;
return true;
}
}
}
class Child extends Mother
{
public function __set($property, $value)
{
switch ($property) {
case 'foo':
throw new Exception('Foo is not allowed to set');
}
return parent::__set($property, $value);
}
}
This means, Child behaves more strict than Mother and breaks the
principle.
With advanced properties, the interpreter could at least verify that
getting/setting properties is not stricter in subclasses.
SO far, Lars
Attachment: [application/pgp-signature] Dies ist ein digital signierter Nachrichtenteil signature.asc
Attachment: [application/pgp-signature] Dies ist ein digital signierter Nachrichtenteil signature.asc