This commit is contained in:
Robert Husák 2020-02-07 10:40:42 +01:00
Родитель 85596ae453
Коммит 70190711e7
2 изменённых файлов: 39 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,20 @@
<?php
namespace classes\clone_001;
class A {
var $p;
public function __construct(&$var) {
$this->p =& $var;
}
}
function test() {
$var = 42;
$a = new A($var);
$b = clone $a;
$var = 24;
echo $b->p;
}
test();

Просмотреть файл

@ -73,6 +73,23 @@ class A {
$this->p =& $p; $this->p =& $p;
$this->foo5($p); $this->foo5($p);
} }
// Modification in __clone
public function __clone() {
$this->p = 666;
}
private function foo6($p) {
$that = clone $this;
echo $p;
}
public function test6() {
$p = 42;
$this->p =& $p;
$this->foo6($p);
}
} }
(new A)->test1(); (new A)->test1();
@ -84,3 +101,5 @@ echo "\n";
(new A)->test4(); (new A)->test4();
echo "\n"; echo "\n";
(new A)->test5(); (new A)->test5();
echo "\n";
(new A)->test6();