Home > Backend Development > PHP Tutorial > Simple usage of PHP single state mode

Simple usage of PHP single state mode

墨辰丷
Release: 2023-03-28 14:54:01
Original
1355 people have browsed it

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template