Hi,

that's imho expected behaviour. To quote
http://www.php.net/zend-engine-2.php
| Protected member variables can be accessed in classes extending the class
| they are declared in, whereas private member variables can only be
| accessed by the class they belong to.   

And $id belongs to the base class and not to the extended. What else should
be the difference between private and protected? 

johannes

Antony Dovgal wrote:

> Hi all!
> 
> What do you expect from this code?
> 
> <?php
> 
> class Foo{
> private $id = false;
> public function getId () {
> return $this->id;
> }
> public function setId ($id) {
> return $this->id = $id;
> }
> 
> }
> 
> class Bar extends Foo {
> public function setId ($id) {
> return $this->id = $id;
> }
> }
> 
> $b = new Bar;
> $b->setId(123);
> var_dump($b->getId());
> 
> ?>
> 
> It outputs 'bool(false)', while I expect it to print 'int(123)'.
> 
> Changing private $id to public or protected solves the problem.
> Adding getId() method to the Bar solves it too, but this is obviously
> rather silly solution.
> 
> Am I missing something and this is really expected behaviour ?
> 
> ---
> WBR,
> Antony Dovgal aka tony2001
> [EMAIL PROTECTED] || [EMAIL PROTECTED]

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

Reply via email to