note 93097 added to language.oop5.decon

From: Date: Sun, 23 Aug 2009 14:05:14 +0000
Subject: note 93097 added to language.oop5.decon
Groups: php.notes 
Request: Send a blank email to php-notes+get-159800@lists.php.net to get a copy of this message
It's usefull to note that parent::__construct() is executed like a standalone function called into the new one, and not like a first part of the code. So "return" or "die()" don't have effect on following code. If you want to avoid the execution of the child constructor you have to pass some condition from the parent. Example: class X { function X(){ if($_POST['break']=='yes'){return;} } } class Y extends X{ function Y(){ parent::__construct(); print("Y_constructor_finished"); } } $_POST['break']=='yes'; $new_Y=new Y(); // will print "Y_constructor_finished" Solution: class X { function X(){ if($_POST['break']=='yes'){$this->break='yes';return;} } } class Y extends X{ function Y(){ parent::__construct(); if($this->break=='yes'){return;} print("Y_constructor_finished"); } } $_POST['break']='yes'; $new_Y=new Y(); // will print nothing ---- Server IP: 80.241.173.5 Probable Submitter: 194.242.212.33 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php Edit -- https://master.php.net/note/edit/93097 Del: integrated -- https://master.php.net/note/delete/93097/integrated Del: useless -- https://master.php.net/note/delete/93097/useless Del: bad code -- https://master.php.net/note/delete/93097/bad+code Del: spam -- https://master.php.net/note/delete/93097/spam Del: non-english -- https://master.php.net/note/delete/93097/non-english Del: in docs -- https://master.php.net/note/delete/93097/in+docs Del: other reasons-- https://master.php.net/note/delete/93097 Reject -- https://master.php.net/note/reject/93097 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159800) next »