Simple question about PHP4 inheritance

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Simple question about PHP4 inheritance

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Yes, methods override methods of the same name in the parent class in PHP4.
(#10850)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Thanks
Post Reply