<?php
class SubObject
{
static $instances = 0;
public $instance;
public function __construct() {
$this->instance = ++self::$instances;
}
}
class MyCloneable
{
public $object1;
public $object2;
function __clone()
{
// forza la copia di $this->object1, che altrimenti
// punterebbe alla stessa istanza.
$this->object1 = clone $this->object1;
}
/*public function __invoke($object1,$object2)
{
$this->oject1=$object1;
$this->oject2=$object2;
}
*/
}
$obj = new MyCloneable();
$obj3 = clone $obj;
$obj->object1 = new SubObject();
$obj->object2 = new SubObject();
$obj3 = clone $obj;
$obj2=new $obj;
$obj2->object1 = new SubObject();
$obj2->object2 = new SubObject();
print("Oggetto originale:\n");
print_r($obj);
print("Oggetto originale:\n");
print_r($obj2);
print("Oggetto clonato:\n");
print_r($obj3);
?>
Fatal error: Uncaught Error: __clone method called on non-object in /in/F4ovb:21
Stack trace:
#0 /in/F4ovb(33): MyCloneable->__clone()
#1 {main}
thrown in /in/F4ovb on line 21
Process exited with code 255.
Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/F4ovb on line 4
Process exited with code 255.
Parse error: parse error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/F4ovb on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/F4ovb on line 4
Process exited with code 255.