@@ -73,6 +73,10 @@ 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_date_immutable_ce ;
78+ zend_class_entry * php_phongo_json_serializable_ce ;
79+
7680php_phongo_server_description_type_map_t
7781php_phongo_server_description_type_map [PHONGO_SERVER_DESCRIPTION_TYPES ] = {
7882 { PHONGO_SERVER_UNKNOWN , "Unknown" },
@@ -1854,6 +1858,25 @@ PHP_GINIT_FUNCTION(mongodb)
18541858}
18551859/* }}} */
18561860
1861+ static zend_class_entry * php_phongo_fetch_internal_class (const char * class_name , size_t class_name_len TSRMLS_DC )
1862+ {
1863+ #if PHP_VERSION_ID >= 70000
1864+ zend_class_entry * pce ;
1865+
1866+ if ((pce = zend_hash_str_find_ptr (CG (class_table ), class_name , class_name_len ))) {
1867+ return pce ;
1868+ }
1869+ #else
1870+ zend_class_entry * * pce ;
1871+
1872+ if (zend_hash_find (CG (class_table ), class_name , class_name_len + 1 , (void * * ) & pce ) == SUCCESS ) {
1873+ return * pce ;
1874+ }
1875+ #endif
1876+
1877+ return NULL ;
1878+ }
1879+
18571880/* {{{ PHP_MINIT_FUNCTION */
18581881PHP_MINIT_FUNCTION (mongodb )
18591882{
@@ -1886,6 +1909,25 @@ PHP_MINIT_FUNCTION(mongodb)
18861909 phongo_std_object_handlers.get_closure = NULL;
18871910 */
18881911
1912+ /* Initialize zend_class_entry dependencies.
1913+ *
1914+ * Although DateTimeImmutable was introduced in PHP 5.5.0,
1915+ * php_date_get_immutable_ce() is not available in PHP versions before
1916+ * 5.5.24 and 5.6.8.
1917+ *
1918+ * Although JsonSerializable was introduced in PHP 5.4.0,
1919+ * php_json_serializable_ce is not exported in PHP versions before 5.4.26
1920+ * and 5.5.10. For later PHP versions, looking up the class manually also
1921+ * helps with distros that disable LTDL_LAZY for dlopen() (e.g. Fedora).
1922+ */
1923+ php_phongo_date_immutable_ce = php_phongo_fetch_internal_class (ZEND_STRL ("datetimeimmutable" ) TSRMLS_CC );
1924+ php_phongo_json_serializable_ce = php_phongo_fetch_internal_class (ZEND_STRL ("jsonserializable" ) TSRMLS_CC );
1925+
1926+ if (php_phongo_json_serializable_ce == NULL ) {
1927+ zend_error (E_ERROR , "JsonSerializable class is not defined. Please ensure that the 'json' module is loaded before the 'mongodb' module." );
1928+ return FAILURE ;
1929+ }
1930+
18891931 PHP_MINIT (bson )(INIT_FUNC_ARGS_PASSTHRU );
18901932
18911933 PHP_MINIT (Type )(INIT_FUNC_ARGS_PASSTHRU );
0 commit comments