Bug #66023 [Opn->Dup]: destruction problem

From: Date: Sat, 26 Mar 2016 23:44:47 +0000
Subject: Bug #66023 [Opn->Dup]: destruction problem
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200134@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66023&edit=1 ID: 66023 Updated by: nikic@php.net Reported by: flobee at gmail dot com Summary: destruction problem -Status: Open +Status: Duplicate Type: Bug Package: *General Issues Operating System: debian testing PHP Version: 5.5.5 Block user comment: N Private report: N New Comment: Duplicate of bug #53769. Previous Comments: ------------------------------------------------------------------------ [2013-11-11 18:34:56] flobee at gmail dot com note, i just found some hints in my code and which make me think the following: public function __destruct() { // does not work; looses mysql-link first well, so: custom code stays longer (in a kind of way to be used) than php and the needed functionality. this is the same with the session. Am I wrong or missing some docs for that kind of reasons? ------------------------------------------------------------------------ [2013-11-03 00:07:48] flobee at gmail dot com Description: ------------ calling methodes on destruction is difficult to understand when using singelton patterns which does not make sence for me. maybe i'm wrong.. i'm not sure at the moment... also: if session is used this fails on destruction see script below for a simple test i expect the call of knock() from master class on destruction of class b. when not using singelton patter all is fine. the order of the destruction works. this problems starts with php 5.5* packages in debian testing. $ uname -a Linux d1 3.10-3-686-pae #1 SMP Debian 3.10.11-1 (2013-09-10) i686 GNU/Linux $ php -v PHP 5.5.5-1 (cli) (built: Oct 19 2013 22:09:48) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans Test script: --------------- <?php error_reporting( -1); session_start(); interface Singleton_Interface { public static function getInstance(); } abstract class Singleton implements Singleton_Interface { public function __clone() { throw new Exception( 'Clone is not allowed.' ); } } class master extends Singleton implements Singleton_Interface { private $r; private static $instance; public static function getInstance( $params=array( ) ) { if( !isset(self::$instance) ) { $c = __CLASS__; self::$instance = new $c($params); } return self::$instance; } public function knock() { echo 'call ' . __METHOD__ . PHP_EOL; } public function __construct($r=false) { $this->r = $r; echo __METHOD__ . PHP_EOL; } public function __destruct() { echo __METHOD__ . PHP_EOL; if (method_exists($this->r, 'knock')) { $this->r->knock(); } $_SESSION['x'] = __METHOD__; } } class b extends Singleton implements Singleton_Interface { private $r; private static $instance; public static function getInstance( $params=array( ) ) { if( !isset(self::$instance) ) { $c = __CLASS__; self::$instance = new $c($params); } return self::$instance; } public function knock() { echo 'call ' . __METHOD__ . PHP_EOL; } public function __construct($r=false) { $this->r = $r; echo __METHOD__ . PHP_EOL; } public function __destruct() { echo __METHOD__ . PHP_EOL; if (method_exists($this->r, 'knock')) { $this->r->knock(); } $_SESSION['y'] = __METHOD__; } } header( 'content-type: text/plain' ); echo 'session:'; print_r($_SESSION); $master = master::getInstance(); $b = b::getInstance($master); // calls master->knock() on destruction $master->knock(); $b->knock(); echo 'done' . PHP_EOL; Actual result: -------------- /* result: master::__construct b::__construct call master::knock call b::knock done master::__destruct b::__destruct call master::knock <------ no error? _session is empty! correct? wrong? */ ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66023&edit=1

« previous php.bugs (#200134) next »