@@ -1906,9 +1906,11 @@ static bool php_phongo_apply_wc_options_to_client(mongoc_client_t *client, bson_
19061906static mongoc_client_t * php_phongo_make_mongo_client (php_phongo_manager_t * manager , const mongoc_uri_t * uri , zval * driverOptions TSRMLS_DC ) /* {{{ */
19071907{
19081908#if PHP_VERSION_ID >= 70000
1909- zval * tmp ;
1909+ zval * zdebug = NULL ;
1910+ zval * zcontext = NULL ;
19101911#else
1911- zval * * tmp ;
1912+ zval * * zdebug = NULL ;
1913+ zval * * zcontext = NULL ;
19121914#endif
19131915 php_stream_context * ctx = NULL ;
19141916 const char * mech , * mongoc_version , * bson_version ;
@@ -1917,30 +1919,31 @@ static mongoc_client_t *php_phongo_make_mongo_client(php_phongo_manager_t *manag
19171919 ENTRY ;
19181920
19191921#if PHP_VERSION_ID >= 70000
1920- if (driverOptions && (tmp = zend_hash_str_find (Z_ARRVAL_P (driverOptions ), "debug" , sizeof ("debug" )- 1 )) != NULL ) {
1922+ if (driverOptions && (zdebug = zend_hash_str_find (Z_ARRVAL_P (driverOptions ), "debug" , sizeof ("debug" )- 1 )) != NULL ) {
19211923 zend_string * key = zend_string_init (PHONGO_DEBUG_INI , sizeof (PHONGO_DEBUG_INI )- 1 , 0 );
1922- zend_string * value_str = zval_get_string (tmp );
1924+ zend_string * value_str = zval_get_string (zdebug );
19231925 zend_alter_ini_entry_ex (key , value_str , PHP_INI_USER , PHP_INI_STAGE_RUNTIME , 0 );
19241926 zend_string_release (key );
19251927 zend_string_release (value_str );
19261928 }
19271929#else
1928- if (driverOptions && zend_hash_find (Z_ARRVAL_P (driverOptions ), "debug" , strlen ("debug" ) + 1 , (void * * )& tmp ) == SUCCESS ) {
1929- convert_to_string (* tmp );
1930+ if (driverOptions && zend_hash_find (Z_ARRVAL_P (driverOptions ), "debug" , strlen ("debug" ) + 1 , (void * * )& zdebug ) == SUCCESS ) {
1931+ convert_to_string (* zdebug );
19301932
1931- zend_alter_ini_entry_ex ((char * )PHONGO_DEBUG_INI , sizeof (PHONGO_DEBUG_INI ), Z_STRVAL_PP (tmp ), Z_STRLEN_PP (tmp ), PHP_INI_USER , PHP_INI_STAGE_RUNTIME , 0 TSRMLS_CC );
1933+ zend_alter_ini_entry_ex ((char * )PHONGO_DEBUG_INI , sizeof (PHONGO_DEBUG_INI ), Z_STRVAL_PP (zdebug ), Z_STRLEN_PP (zdebug ), PHP_INI_USER , PHP_INI_STAGE_RUNTIME , 0 TSRMLS_CC );
19321934 }
19331935#endif
19341936
19351937#if PHP_VERSION_ID >= 70000
1936- if (driverOptions && (tmp = zend_hash_str_find (Z_ARRVAL_P (driverOptions ), "context" , sizeof ("context" )- 1 )) != NULL ) {
1937- ctx = php_stream_context_from_zval (tmp , 0 );
1938+ if (driverOptions && (zcontext = zend_hash_str_find (Z_ARRVAL_P (driverOptions ), "context" , sizeof ("context" )- 1 )) != NULL ) {
1939+ ctx = php_stream_context_from_zval (zcontext , 0 );
19381940#else
1939- if (driverOptions && zend_hash_find (Z_ARRVAL_P (driverOptions ), "context" , strlen ("context" ) + 1 , (void * * )& tmp ) == SUCCESS ) {
1940- ctx = php_stream_context_from_zval (* tmp , 0 );
1941+ if (driverOptions && zend_hash_find (Z_ARRVAL_P (driverOptions ), "context" , strlen ("context" ) + 1 , (void * * )& zcontext ) == SUCCESS ) {
1942+ ctx = php_stream_context_from_zval (* zcontext , 0 );
19411943#endif
19421944 } else {
1943- GET_DEFAULT_CONTEXT ();
1945+ zval * tmp = NULL ; /* PHP 5.x requires an lvalue */
1946+ ctx = php_stream_context_from_zval (tmp , 0 );
19441947 }
19451948
19461949 if (mongoc_uri_get_ssl (uri )) {
@@ -2041,6 +2044,17 @@ bool phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
20412044 return false;
20422045 }
20432046
2047+ /* Keep a reference to driverOptions, since it may be referenced later for
2048+ * lazy stream initialization. */
2049+ if (driverOptions ) {
2050+ #if PHP_VERSION_ID >= 70000
2051+ ZVAL_COPY (& manager -> driverOptions , driverOptions );
2052+ #else
2053+ Z_ADDREF_P (driverOptions );
2054+ manager -> driverOptions = driverOptions ;
2055+ #endif
2056+ }
2057+
20442058 return true;
20452059} /* }}} */
20462060
0 commit comments