note 26481 added to language.oop

From: Date: Fri, 01 Nov 2002 05:13:02 +0000
Subject: note 26481 added to language.oop
Groups: php.notes 
Request: Send a blank email to php-notes+get-38853@lists.php.net to get a copy of this message
The workarounds for chaining/inheriting constructors in here didn't work for me when I tried them. After a while, I found a different way to make sure the parent class constructor was called: Unserializing the child class instance from a (new) parent class instance and then executing its own initialization: <?php ... class THECHILD extends THEPARENT { var $abc; var $xyz = "xyz"; // NOTE: this value will be lost during unserialization function _ATOM() { // NOTE: $this->xyz is now "xyz" $this = unserialize (serialize (new THEPARENT())); // NOTE: Original value of $this->xyz is lost $this->$abc = "abc"; // Better: initialize values after ser/unser. step } } ... ?> Not the fastest to execute maybe, but it seems (!) to work fine. The pro's: - Not as much typing and - Not as confusing to read as some other solutions I've found. -- http://www.php.net/manual/en/language.oop.php http://master.php.net/manage/user-notes.php?action=edit+26481 http://master.php.net/manage/user-notes.php?action=delete+26481 http://master.php.net/manage/user-notes.php?action=reject+26481

« previous php.notes (#38853) next »