note 57584 added to function.is-a

From: Date: Sat, 08 Oct 2005 00:18:13 +0000
Subject: note 57584 added to function.is-a
Groups: php.notes 
Request: Send a blank email to php-notes+get-96591@lists.php.net to get a copy of this message
Lazy Instantiation using is_a() and php5 <?php class ObjectA { public function print_line($text) { print $text . "\n"; } } class ObjectB { public function ObjectA() { static $objecta; if (!is_a('ObjectA', $objecta)) { $objecta = new ObjectA; } return $objecta; } } $obj = new ObjectB; $obj->ObjectA()->print_line('testing, 1 2 3'); ?> In the above example, ObjectA is not instantiated until needed by ObjectB. Then ObjectB can continually use it's creation as needed without reinstantiating it. There are other ways, but I like this one :-) ---- Manual Page -- http://www.php.net/manual/en/function.is-a.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57584 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57584&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57584&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57584&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57584&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57584&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57584&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57584&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57584&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96591) next »