D
D
DjimiDjimi2018-03-24 16:26:11
PHP
DjimiDjimi, 2018-03-24 16:26:11

How to remove a static instance of a class in PHP?

How to remove a static instance of a class? I create it like this

<?php

class MyClass
{
protected static $myclass;
public static function instanceClass()
  {
        if (is_null(self::$myclass)) { 
            self::$myclass= new self;  
        }
        return self::$myclass;
    }

And how to remove it, except to end the script?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri, 2018-03-24
@DjimiDjimi

For example, create another method with the code
self::$myclass = null;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question