<?php
class fakePDO {
}
class DatabaseConnection {
protected $connection;
public function __construct() {
$connection = new fakePDO();
}
public function __destruct() {
unset($this->connection);
}
}
class Database {
static $connections = array();
public static function open($key) {
self::$connections[$key] = new DatabaseConnection();
}
public static function close($key) {
unset(self::$connections[$key]);
gc_collect_cycles();
}
}
Database::open('a');
Database::open('b');
Database::close('a');
debug_zval_dump(Database::$connections);
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array(1) refcount(2){
["b"]=>
object(DatabaseConnection)#2 (1) refcount(1){
["connection":protected]=>
NULL
}
}
Fatal error: Call to undefined function gc_collect_cycles() in /in/1vSZY on line 34
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/1vSZY on line 9
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/1vSZY on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/1vSZY on line 9
Process exited with code 255.