On Wed, 2004-04-07 at 17:07, Richard Lewis wrote:
> What do members think that this code should do:
>
> class A
> {
> var $a, $b;
> function A($a)
> {
> $this->$a = $a;
> }
> function prnt()
> {
> echo "<br>a=" . $this->$a;
> }
> }
>
> class B extends A
> {
> function B($a, $b)
> {
> parent::A($a);
> $this->$b = $b;
> }
> function prnt()
> {
> parent::prnt();
> echo "<br>b=" . $this->$b;
> }
> }
>
> $obj = new B("a","b");
> $obj->prnt();
>
> I think it should print
> a=a
> b=b
>
> but it seems to print (on PHP4)
> a=
> b=
Looks like you're suffering from mad dollar disease. You should have the
following instead:
class A
{
var $a, $b;
function A($a)
{
$this->a = $a;
}
function prnt()
{
echo "<br>a=" . $this->a;
}
}
class B extends A
{
function B($a, $b)
{
parent::A($a);
$this->b = $b;
}
function prnt()
{
parent::prnt();
echo "<br>b=" . $this->b;
}
}
$obj = new B("a","b");
$obj->prnt();
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php