Re: Weird behaviour of private attribute + overloaded method
| From: | Eric Daspet | Date: | Tue, 15 Jun 2004 14:35:06 +0000 |
| Subject: | Re: Weird behaviour of private attribute + overloaded method | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-10471@lists.php.net to get a copy of this message | ||
Antony Dovgal wrote:
It outputs 'bool(false)', while I expect it to print 'int(123)'.Foo::id is private so Bar::setId() cannot use it. It uses an implicit public Bar::id (different from Foo::id). Foo::getId() correctly read the private attribute Foo::id (not the public Bar::id) and return it.
Am I missing something and this is really expected behaviour ?I think it is. - if we allow Bar::setId() to change Foo::id, "private" keyword is useless - if we allow Foo::getId() to read Bar::id instead of Foo:id, then a derived class can pertubate private things in the mother class (which is not a good solution). -- Eric Daspet