PHP/Class/ clone — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 10:00, 26 мая 2010
Using the __clone() Method
<source lang="html4strict">
<?php
class myObject { public $var_one = 10; public $var_two = 20; function __clone() { $this->var_two = 0; } } $inst_one = new myObject(); $inst_two = clone $inst_one; var_dump($inst_one); var_dump($inst_two);
?>
</source>
Using the clone Statement
<source lang="html4strict">
<?php
class Integer { private $number; public function getInt() { return (int)$this->number; } public function setInt($num) { $this->number = (int)$num; } } $class_one = new Integer(); $class_one_copy = clone $class_one;
?>
</source>