Weird behaviour of private attribute + overloaded method
| From: | Antony Dovgal | Date: | Tue, 15 Jun 2004 13:59:18 +0000 |
| Subject: | Weird behaviour of private attribute + overloaded method | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-10468@lists.php.net to get a copy of this message | ||
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
tony2001@phpclub.net || antony@dovgal.com