note 47750 added to language.oop5.decon
| From: | lenix at osu1 dot php dot net | Date: | Sun, 28 Nov 2004 04:38:56 +0000 |
| Subject: | note 47750 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81111@lists.php.net to get a copy of this message | ||
i just found out that, together with the 'final' keyword, it gets pretty easy to write a
parent-class with a constructor always called and not overwriteable by any childs extending that
class.
<?php
abstract class Foo {
final function __construct( $Bar ) {
echo "Foo::__construct( $Bar );<br />\n";
}
}
class Baz extends Foo {
public function printBaz( $Val = "" ) {
echo "Baz::printBaz( $Val );<br />\n";
}
}
try {
$Obj =& new Baz( "Passed to new Baz( )" );
$Obj->printBaz( "method of Baz" );
} catch ( Exception $E ) {
echo 'Caught exception: ', $E->getMessage(), "<\n";
}
?>
of course subclasses are forced that way to have no contructor on their own.
----
Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47750
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47750&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47750&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47750&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47750&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47750&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47750&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47750&report=yes
Search -- http://master.php.net/manage/user-notes.php