note 47750 deleted from language.oop5.decon by felipe

From: Date: Mon, 24 Mar 2008 22:44:35 +0000
Subject: note 47750 deleted from language.oop5.decon by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137507@lists.php.net to get a copy of this message
Note Submitter: lenix ---- 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.

« previous php.notes (#137507) next »