PHP 5 introduces the final keyword, which prevents child classes from
overriding a method by prefixing the definition with final. If the class
itself is being defined final then it cannot be extended.
Example 19-28. Final methods example |
<?php
class BaseClass {
public function test() {
echo "BaseClass::test() called\n";
}
final public function moreTesting() {
echo "BaseClass::moreTesting() called\n";
}
}
class ChildClass extends BaseClass {
public function moreTesting() {
echo "ChildClass::moreTesting() called\n";
}
}
?>
|
|
Example 19-29. Final class example |
<?php
final class BaseClass {
public function test() {
echo "BaseClass::test() called\n";
}
final public function moreTesting() {
echo "BaseClass::moreTesting() called\n";
}
}
class ChildClass extends BaseClass {
}
?>
|
|