Issues

ZF-11463: Undefined class constant | SaveHandler

Description

Error shows after Zend_Exception is thrown. Undefined class constant 'PRIMARY_TYPE_NUM' in /library/Zend/Session/SaveHandler/DbTable.php on line 522

Comments

Could you provide some sample code showing how you're using Zend_Session_SaveHandler_DbTable, how you handle the exception, and some information on the exception that was thrown? (esp: the class name and stack trace)

We're running into the same issue. It's just a fatal error, there's no exception. We're using Zend Framework 1.9.7

Error occurs on a PHP 5.3.3 server. Same code runs fine on a PHP 5.3.6 server

Error log:


[27-Jun-2011 11:15:25] PHP Fatal error:  Undefined class constant 'PRIMARY_TYPE_NUM' in /home/......../libraries/Zend/1.9.7/Zend/Session/SaveHandler/DbTable.php on line 522

Server having fatal error:


PHP 5.3.3 (cli) (built: Aug  7 2010 14:49:50)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Server running fine:


PHP 5.3.6 (cli) (built: Mar 19 2011 07:44:03)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
    with the ionCube PHP Loader v4.0.9, Copyright (c) 2002-2011, by ionCube Ltd., and
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

@Tibo: Can you try it on PHP 5.3.3 with the latest ZF release? (or better yet, against SVN trunk)

I can't reproduce the issue against trunk on my dev machine:


PHP 5.3.3 (cli) (built: Jan 28 2011 14:53:13)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with the ionCube PHP Loader v4.0.5, Copyright (c) 2002-2011, by ionCube Ltd., and
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

Hi,

I've discovered this issue few mins ago and found solution. checked with PHP 5.3.3 and ZF 1.11.7 & 1.11.8

How to reproduce: - use DbTable handler - trigger fatal error - see error message describer above

After debugging noticed that object is already destroyed and it does not have any static properties.

 
protected function _getPrimary($id, $type = null)
{
    $refl = new ReflectionClass($this);

    error_log('CHECK: '.print_r($refl->getConstants(),1));

    ... rest code ...
}
[08-Jul-2011 11:38:31] PHP Fatal error:  xxx in /path/app/module/default/action/IndexController.php on line 26
[08-Jul-2011 11:38:31] PHP Stack trace: [clipped]
[08-Jul-2011 11:38:31] CHECK: Array()
[08-Jul-2011 11:38:31] PHP Fatal error:  Undefined class constant 'PRIMARY_TYPE_NUM' in /path/lib/Zend/Session/SaveHandler/DbTable.php on line 525
[08-Jul-2011 11:38:31] PHP Stack trace: [clipped]

Workaround is taken from php.net manual.

Pay attention to this note: {panel:title=http://php.net/manual/en/…} As of PHP 5.0.5 the write and close handlers are called after object destruction and therefore cannot use objects or throw exceptions. The object destructors can however use sessions. {panel}

By setting shutdown callback as: register_shutdown_function('session_write_close'); in the entry point (index.php) you avoid this issue.

Have a nice day, Nick

UPD. forgot to mention - front controller should be set to throw exceptions, aka in development mode.

I get the same errror. This is quite strange as the user has SELECT rights.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'green'@'localhost' for table 'application__users'' in /var/opt/ZendFramework/trunk/library/Zend/Db/Statement/Pdo.php:228

Stack trace: #0 /var/opt/ZendFramework/trunk/library/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array) #1 /var/opt/ZendFramework/trunk/library/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array) #2 /var/opt/ZendFramework/trunk/library/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array) #3 /var/opt/ZendFramework/trunk/library/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('DESCRIBE mydb...', Array) #4 /var/opt/ZendFramework/trunk/library/Zend/Db/Adapter/Pdo/Mysql.php(169): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBEmydb...') #5 /var/opt/ZendFramework/trunk/library/Zend/Db/Table/Abstract.php(835): Zend_Db_Adapter_Pdo_Mysql->describeTable('application__us...', 'mydb') #6 /var/opt/ZendFra in /var/opt/ZendFramework/trunk/library/Zend/Controller/Plugin/Broker.php on line 312 Fatal error: Undefined class constant 'PRIMARY_TYPE_NUM' in /var/opt/ZendFramework/trunk/library/Zend/Session/SaveHandler/DbTable.php on line 522

This exception seems to pop up only when another (fatal) error occurs before that.