note 26481 deleted from language.oop by aidan
| From: | aidan@php.net | Date: | Sat, 03 Jul 2004 14:56:25 +0000 |
| Subject: | note 26481 deleted from language.oop by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72460@lists.php.net to get a copy of this message | ||
Note Submitter: smurge@REMOVETHISweb.de
----
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.