From: flobee at gmail dot com Operating system: debian testing PHP version: 5.5.5 Package: *General Issues Bug Type: Bug Bug description:destruction problem
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 bug report at https://bugs.php.net/bug.php?id=66023&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66023&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66023&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66023&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66023&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66023&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66023&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66023&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66023&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66023&r=support Expected behavior: https://bugs.php.net/fix.php?id=66023&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66023&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66023&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66023&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66023&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66023&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66023&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66023&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66023&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66023&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66023&r=mysqlcfg