Copy CodeThe code is as follows:
/**
* Prototype mode
*
* Use the prototype instance to specify the kind of object to create. and create new objects by copying this prototype
*
*/
Abstract class Prototype
{
Private $_id = null;
Public function __construct ($id)
{
$this->_id = $id;
}
Public Function GetID ()
{
return $this->_id;
}
Public Function __clone ()//Magic function
{
$this->_id + = 1;
}
Public Function Getclone ()
{
return clone $this;
}
}
Class Concreteprototype extends Prototype
{
}
//
$objPrototype = new Concreteprototype (0);
$objPrototype 1 = clone $objPrototype;
echo $objPrototype 1->getid (). "
";
$objPrototype 2 = $objPrototype;
echo $objPrototype 2->getid (). "
";
$objPrototype 3 = $objPrototype->getclone ();
echo $objPrototype 3->getid (). "
";
The above describes the prototype.js PHP design pattern Prototype prototype code, including the prototype.js aspect of the content, I hope that the PHP tutorial interested in a friend helpful.