note 61691 added to language.oop5.decon

From: Date: Thu, 09 Feb 2006 18:55:42 +0000
Subject: note 61691 added to language.oop5.decon
Groups: php.notes 
Request: Send a blank email to php-notes+get-103380@lists.php.net to get a copy of this message
(Refering to: caliban at darklock dot com) To force a constructor always to be called, and still be able to define a constructor on a derived class use the model below. Ideal for module architectures, because you only have to know the file and classname to construct an object. <?php class Parameter {} abstract class BaseClass { protected $param; public final function __construct( Parameter $param ) { $this->param = $param; $this->pseudoConstruct(); } protected abstract function pseudoConstruct(); } class ConcreteClass extends BaseClass { protected function pseudoConstruct() { echo __CLASS__.' constructor'; } } $refl = new ReflectionClass( 'ConcreteClass' ); if( !$refl->isSubclassOf( 'BaseClass' ) ) throw new Exception( 'Invalid base class!' ); $refl->newInstance( new Parameter() ); ?> ---- Server IP: 194.109.193.119 Probable Submitter: 80.56.173.209 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61691 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61691&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61691&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61691&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61691&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61691&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61691&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61691&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61691&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103380) next »