Created a reference on using the final keyword.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@164118 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Jon Wood 2004-07-23 18:16:04 +00:00
parent 54c87abd60
commit 32df432bac

View file

@ -1,11 +1,37 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.1 $ -->
<!-- $Revision: 1.2 $ -->
<sect1 id="language.oop5.final">
<title>Final Keyword</title>
<para>
.
PHP 5 introduces the final keyword, which prevents child classes from
overriding a method or variable by prefixing the definition with final.
</para>
<example>
<title>Abstract class example</title>
<programlisting role="php">
<![CDATA[
<?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";
}
}
// Results in Fatal error: Cannot override final method BaseClass::moreTesting()
?>
]]>
</programlisting>
</example>
</sect1>