search

Home  >  Q&A  >  body text

I don't understand the meaning of judging whether it is a static instance? ?

One ($instance =null;) has been defined above

Judgment (self::$instance instanceof self) is definitely (false)

Why do we still need to judge?

Isn’t it enough to directly assign the current object instance to (self::$instance) and then return the value?

self::$instance =new self($sitename);
return self::$instance;


God_LikeGod_Like2114 days ago1407

reply all(1)I'll reply

  • **少女欢乐多

    **少女欢乐多2020-01-28 12:37:11

    That’s why we need the singleton mode. If we assign values ​​repeatedly, it will become multiple instances

    reply
    0
  • Cancelreply