Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Deepcopy/PHP/deepcopy-1.php
Normal file
21
Task/Deepcopy/PHP/deepcopy-1.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
class Foo
|
||||
{
|
||||
public function __clone()
|
||||
{
|
||||
$this->child = clone $this->child;
|
||||
}
|
||||
}
|
||||
|
||||
$object = new Foo;
|
||||
$object->some_value = 1;
|
||||
$object->child = new stdClass;
|
||||
$object->child->some_value = 1;
|
||||
|
||||
$deepcopy = clone $object;
|
||||
$deepcopy->some_value++;
|
||||
$deepcopy->child->some_value++;
|
||||
|
||||
echo "Object contains {$object->some_value}, child contains {$object->child->some_value}\n",
|
||||
"Clone of object contains {$deepcopy->some_value}, child contains {$deepcopy->child->some_value}\n";
|
||||
?>
|
||||
14
Task/Deepcopy/PHP/deepcopy-2.php
Normal file
14
Task/Deepcopy/PHP/deepcopy-2.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
// stdClass is a default PHP object
|
||||
$object = new stdClass;
|
||||
$object->some_value = 1;
|
||||
$object->child = new stdClass;
|
||||
$object->child->some_value = 1;
|
||||
|
||||
$deepcopy = unserialize(serialize($object));
|
||||
$deepcopy->some_value++;
|
||||
$deepcopy->child->some_value++;
|
||||
|
||||
echo "Object contains {$object->some_value}, child contains {$object->child->some_value}\n",
|
||||
"Clone of object contains {$deepcopy->some_value}, child contains {$deepcopy->child->some_value}\n";
|
||||
Loading…
Add table
Add a link
Reference in a new issue