note 81141 added to language.oop5.basic
| From: | david dot schueler at tel-billig dot de | Date: | Fri, 15 Feb 2008 14:16:57 +0000 |
| Subject: | note 81141 added to language.oop5.basic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136172@lists.php.net to get a copy of this message | ||
If you just want to create a new object that extends another object and you want to copy all
variables from the father object, you may use this piece of code:
<?php
$father =& new father();
$father->a_var = "Hello World.";
$son = new son($event);
$son->say_hello();
class father {
public $a_var;
}
class son extends father {
public function __construct($father_class) {
foreach ($father_class as $variable=>$value) {
$this->$variable = $value;
}
}
public function say_hello() {
echo "Son says: ".$this->a_var;
}
}
?>
This outputs:
Son says: Hello World.
So you dont have to clone the entire object to get the contents of the variables from the father
object.
----
Server IP: 212.124.37.9
Probable Submitter: 84.184.72.27
----
Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php
Edit -- https://master.php.net/note/edit/81141
Del: integrated -- https://master.php.net/note/delete/81141/integrated
Del: useless -- https://master.php.net/note/delete/81141/useless
Del: bad code -- https://master.php.net/note/delete/81141/bad+code
Del: spam -- https://master.php.net/note/delete/81141/spam
Del: non-english -- https://master.php.net/note/delete/81141/non-english
Del: in docs -- https://master.php.net/note/delete/81141/in+docs
Del: other reasons-- https://master.php.net/note/delete/81141
Reject -- https://master.php.net/note/reject/81141
Search -- https://master.php.net/manage/user-notes.php