@@ -73,6 +73,9 @@ ZEND_DECLARE_MODULE_GLOBALS(mongodb)
7373#endif
7474#endif
7575
76+ /* Declare zend_class_entry dependencies, which are initialized in MINIT */
77+ zend_class_entry * php_phongo_json_serializable_ce ;
78+
7679php_phongo_server_description_type_map_t
7780php_phongo_server_description_type_map [PHONGO_SERVER_DESCRIPTION_TYPES ] = {
7881 { PHONGO_SERVER_UNKNOWN , "Unknown" },
@@ -1854,6 +1857,25 @@ PHP_GINIT_FUNCTION(mongodb)
18541857}
18551858/* }}} */
18561859
1860+ static zend_class_entry * php_phongo_fetch_internal_class (const char * class_name , size_t class_name_len TSRMLS_DC )
1861+ {
1862+ #if PHP_VERSION_ID >= 70000
1863+ zend_class_entry * pce ;
1864+
1865+ if ((pce = zend_hash_str_find_ptr (CG (class_table ), class_name , class_name_len ))) {
1866+ return pce ;
1867+ }
1868+ #else
1869+ zend_class_entry * * pce ;
1870+
1871+ if (zend_hash_find (CG (class_table ), class_name , class_name_len + 1 , (void * * ) & pce ) == SUCCESS ) {
1872+ return * pce ;
1873+ }
1874+ #endif
1875+
1876+ return NULL ;
1877+ }
1878+
18571879/* {{{ PHP_MINIT_FUNCTION */
18581880PHP_MINIT_FUNCTION (mongodb )
18591881{
@@ -1886,6 +1908,20 @@ PHP_MINIT_FUNCTION(mongodb)
18861908 phongo_std_object_handlers.get_closure = NULL;
18871909 */
18881910
1911+ /* Initialize zend_class_entry dependencies.
1912+ *
1913+ * Although JsonSerializable was introduced in PHP 5.4.0,
1914+ * php_json_serializable_ce is not exported in PHP versions before 5.4.26
1915+ * and 5.5.10. For later PHP versions, looking up the class manually also
1916+ * helps with distros that disable LTDL_LAZY for dlopen() (e.g. Fedora).
1917+ */
1918+ php_phongo_json_serializable_ce = php_phongo_fetch_internal_class (ZEND_STRL ("jsonserializable" ) TSRMLS_CC );
1919+
1920+ if (php_phongo_json_serializable_ce == NULL ) {
1921+ zend_error (E_ERROR , "JsonSerializable class is not defined. Please ensure that the 'json' module is loaded before the 'mongodb' module." );
1922+ return FAILURE ;
1923+ }
1924+
18891925 PHP_MINIT (bson )(INIT_FUNC_ARGS_PASSTHRU );
18901926
18911927 PHP_MINIT (Type )(INIT_FUNC_ARGS_PASSTHRU );
0 commit comments