I'm currently looking for a way to set a new instance to be the same as an exists instance if already exists.
Is there any easy way as doing something like:
Class Check {
public static $instance = null;
public $name = "";
function __construct($name) {
if (self::$instance !== null) {
$this = self::$instance;
} else {
$this->name = $name;
self::$instance = $this;
}
}
}
$a = new Check("A");
$b = new Check("B");
echo $a->name." = ".$b->name;
to achieve it?
what it returns:
A =
What I want it to return:
A = A
Is it possible to accomplish that? I want that all variables of the older instance to maintain the same.
Thanks in advance.