Page 1 of 1

Simple question about PHP4 inheritance

Posted: Tue May 02, 2006 11:29 am
by Ollie Saunders

Code: Select all

<?php

class foo {
	function zim() {
		echo 'foo';
	}
}

class bar extends foo {
	function zim() {
		echo 'bar';
	}
}

$a = new bar();
$a->zim();

?>
I'm hoping that this code outputs 'bar' in PHP 4. It certainly does in PHP 5 but I don't want to have to install it just to try.
Can anyone tell me?

The manual seems to be somewhat incomplete on the issue of PHP 4 inhertiance and function overriding.

Thanks

Posted: Tue May 02, 2006 11:35 am
by Christopher
Yes, methods override methods of the same name in the parent class in PHP4.

Posted: Tue May 02, 2006 11:37 am
by Ollie Saunders
Thanks