Doc #78451 [NEW]: No possibility make Singleton in the PHP

From: Date: Sat, 24 Aug 2019 11:56:37 +0000
Subject: Doc #78451 [NEW]: No possibility make Singleton in the PHP
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16902@lists.php.net to get a copy of this message
From:             forziforzi at gmail dot com
Operating system: 
PHP version:      7.3.8
Package:          Class/Object related
Bug Type:         Documentation Problem
Bug description:No possibility make Singleton in the PHP

Description:
------------
---
From manual page: https://php.net/class.closure
---

So, no Singleton in the PHP!

Test script:
---------------
<?php

final class A {
    private function __construct() {}
    private function __clone() {
        throw new \Exception('Singleton');
    }
    private function __sleep() {
        throw new \Exception('Singleton');
    }
    private function __wakeup() {
        throw new \Exception('Singleton');
    }
    public static function instantiate() {
        static $obj;
        return $obj = $obj ?? new self;
    }
}

$closure = function () {
    $class = get_class($this);
    return new $class;
};

$obj = A::instantiate();

var_dump($obj);
var_dump($closure->call($obj));



-- 
Edit bug report at https://bugs.php.net/bug.php?id=78451&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=78451&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=78451&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=78451&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=78451&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=78451&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=78451&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=78451&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=78451&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=78451&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=78451&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78451&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=78451&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=78451&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=78451&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=78451&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=78451&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=78451&r=mysqlcfg



Thread (3 messages)

« previous php.doc.bugs (#16902) next »