mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
54c87abd60
commit
32df432bac
1 changed files with 28 additions and 2 deletions
|
@ -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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue