Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class B{
- public $a=0;
- public $b=0;
- }
- class A extends ArrayObject{
- public $genes;
- public $pairs;
- function __construct(){
- $this->pairs = array(new B, new B, new B);
- foreach($this->pairs as &$pair){
- $this->genes[] = &$pair->a;
- $this->genes[] = &$pair->b;
- }
- }
- function __clone() {
- $this->genes = array();
- foreach ($this->pairs as $i => $pair){
- $p = clone $pair;
- $this->pairs[$i] = $p;
- $this->genes[($i )*2] = &$p->a;
- $this->genes[($i+1)*2] = &$p->b;
- }
- }
- }
- $a = new A;
- $a->pairs[1]->a = 11;
- $a->genes[3] = 22;
- echo "print_r(\$a)\n";
- print_r($a);
- $b = clone $a;
- echo "print_r(\$b)\n";
- print_r($b);
- $b->pairs[1]->a = 88;
- $b->genes[3] = 44;
- echo "print_r(\$b)\n";
- print_r($b);
- echo "print_r(\$a)\n";
- print_r($a);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement