This article mainly introduces the simple usage of PHP monomorphic mode, and analyzes the definition and related usage skills of PHP monomorphic mode in the form of examples. Friends in need can refer to it
Monomorphic classes can only Class instantiated once
<?php /* 作者 : shyhero */ class Demo{ private static $ob=null; private $name; private $age; private function __construct(){ } public static function makeOb(){ var_dump($a); if(self::$ob == null){ $c = __CLASS__; self::$ob = new $c(); } return self::$ob; } public function __set($tName,$value){ $this -> $tName = $value; } } $a = Demo::makeOb(); var_dump($a);
The above is the entire content of this article, I hope it will be helpful to everyone's learning.
Related recommendations:
phpQuestions frequently encountered in string reversal interviews
How does PHP get the first non-repeating character in the character stream
PHP uses one line of code to delete all files in the directory
The above is the detailed content of Simple usage of PHP single state mode. For more information, please follow other related articles on the PHP Chinese website!