note 108992 added to language.oop5.basic

From: Date: Mon, 11 Jun 2012 06:32:37 +0000
Subject: note 108992 added to language.oop5.basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-188522@lists.php.net to get a copy of this message
there are time we would like an object to self destruct if the initializing argument provided during object creation, dictate the object should exist at all. <?php class TestClass { private $have_girlfren=false; // private function __construct( $have_girlfren ) { echo "sixth day<br> "; $this->have_girlfren=$have_girlfren; $this->existenceRequirement(); } // private function existenceRequirement() { if( $this->have_girlfren==false ) { echo 'i want to die<br> '; $this->__destruct(); throw new Exception(); } } /////////////////////// function __destruct() { echo "i am dead<br> "; } ////////////////// static function getNewInstance( $have_girlfren) { try{ $new_obj=new TestClass( $have_girlfren); return $new_obj; } catch(Exception $e) { unset($new_obj); echo "rest in peace<br> "; return false; } } // function gotGirlFren() { return $this->have_girlfren; } } $test_obj=TestClass::getNewInstance( false ); if( $test_obj ) echo "bye test oby closing<br> "; else echo "instance commit suicide<br> "; echo "--------------<br> "; echo "-the end--"; ?> ---- Server IP: 124.217.228.174 Probable Submitter: 175.139.220.201 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php Edit -- https://master.php.net/note/edit/108992 Del: integrated -- https://master.php.net/note/delete/108992/integrated Del: useless -- https://master.php.net/note/delete/108992/useless Del: bad code -- https://master.php.net/note/delete/108992/bad+code Del: spam -- https://master.php.net/note/delete/108992/spam Del: non-english -- https://master.php.net/note/delete/108992/non-english Del: in docs -- https://master.php.net/note/delete/108992/in+docs Del: other reasons-- https://master.php.net/note/delete/108992 Reject -- https://master.php.net/note/reject/108992 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188522) next »