PHP: Fatal error: Trying to clone an uncloneable object of class mysqli

July 18, 2009

I was working on a report for a client when I discovered this rather odd error: Fatal error: Trying to clone an uncloneable object of class mysqli. I am still not sure what caused this error, but there does seem to be a quick fix for it.

ini_set('zend.ze1_compatibility_mode', 0);

Here is what the PHP manual has to say about zend.ze1_compatibility_mode:

Name  - zend.ze1_compatibility_mode
Default - "0"
Changeable -  	PHP_INI_ALL
Changelog -  	Available since PHP 5.0.0. Removed in PHP 5.3.0

Enable compatibility mode with Zend Engine 1 (PHP 4). It affects the cloning, casting (objects with no properties cast to
FALSE or 0), and comparing of objects. In this mode, objects are passed by value instead of reference by default.

I hope that helps someone out there.