<?php
class A {
function example() {
echo "I am A::example() and provide basic functionality.<br />\n";
}
}
class B extends A {
function example() {
echo "I am B::example() and provide additional functionality.<br />\n";
}
function main() {
$this->example();
parent::example();
}
}
$b = new B;
// This will call B::example(), which will in turn call A::example().
$b->main();
// Saída:
// I am B::example() and provide additional functionality.
// I am A::example() and provide basic functionality.
PD9waHAKCmNsYXNzIEEgewogICAgZnVuY3Rpb24gZXhhbXBsZSgpIHsKICAgICAgICBlY2hvICJJIGFtIEE6OmV4YW1wbGUoKSBhbmQgcHJvdmlkZSBiYXNpYyBmdW5jdGlvbmFsaXR5LjxiciAvPlxuIjsKICAgIH0KfQoKY2xhc3MgQiBleHRlbmRzIEEgewogICAgZnVuY3Rpb24gZXhhbXBsZSgpIHsKICAgICAgICBlY2hvICJJIGFtIEI6OmV4YW1wbGUoKSBhbmQgcHJvdmlkZSBhZGRpdGlvbmFsIGZ1bmN0aW9uYWxpdHkuPGJyIC8+XG4iOwogICAgfQoKICAgIGZ1bmN0aW9uIG1haW4oKSB7CiAgICAgICAgJHRoaXMtPmV4YW1wbGUoKTsKICAgICAgICBwYXJlbnQ6OmV4YW1wbGUoKTsKICAgIH0KfQoKJGIgPSBuZXcgQjsKCi8vIFRoaXMgd2lsbCBjYWxsIEI6OmV4YW1wbGUoKSwgd2hpY2ggd2lsbCBpbiB0dXJuIGNhbGwgQTo6ZXhhbXBsZSgpLgokYi0+bWFpbigpOwoKLy8gU2HDrWRhOgovLyBJIGFtIEI6OmV4YW1wbGUoKSBhbmQgcHJvdmlkZSBhZGRpdGlvbmFsIGZ1bmN0aW9uYWxpdHkuCi8vIEkgYW0gQTo6ZXhhbXBsZSgpIGFuZCBwcm92aWRlIGJhc2ljIGZ1bmN0aW9uYWxpdHku