Examples:
Inheritance Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <?php class Foo { public function printItem( $string ) { echo 'Foo: ' . $string . PHP_EOL; } public function printPHP() { echo 'PHP is great.' . PHP_EOL; } } class Bar extends Foo { public function printItem( $string ) { echo 'Bar: ' . $string . PHP_EOL; } } $foo = new Foo(); $bar = new Bar(); $foo ->printItem( 'baz' ); // Output: 'Foo: baz' $foo ->printPHP(); // Output: 'PHP is great' $bar ->printItem( 'baz' ); // Output: 'Bar: baz' $bar ->printPHP(); // Output: 'PHP is great' ?> |
Please login to continue.