diff options
| author | Anatol Belski <ab@php.net> | 2016-03-17 12:39:31 +0100 |
|---|---|---|
| committer | Anatol Belski <ab@php.net> | 2016-03-17 12:41:55 +0100 |
| commit | b4eedd128ba9f61be08a50c94afd72837d7cf70b (patch) | |
| tree | 5781b60e54438c633a65b7edfb5b7b2f6f95fc2e /ext/mysqli/mysqli.c | |
| parent | dae086040ecdefcd616c6592679f87f03dc62e00 (diff) | |
| download | php-git-b4eedd128ba9f61be08a50c94afd72837d7cf70b.tar.gz | |
Fixed bug #71820 pg_fetch_object bind parameters before call constructor
If we want to fetch into an object of a custom class that implemens
__set handler, the corstructor has to be called first. The data
passed to the constructor can be possibly required in __set handler.
Diffstat (limited to 'ext/mysqli/mysqli.c')
| -rw-r--r-- | ext/mysqli/mysqli.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index 594dd0da35..a7d81757a7 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -1278,15 +1278,13 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags zval dataset, retval; zend_fcall_info fci; zend_fcall_info_cache fcc; + zend_bool props_handled = 0; ZVAL_COPY_VALUE(&dataset, return_value); - object_and_properties_init(return_value, ce, NULL); if (!ce->default_properties_count && !ce->__set) { Z_OBJ_P(return_value)->properties = Z_ARR(dataset); - } else { - zend_merge_properties(return_value, Z_ARRVAL(dataset)); - zval_ptr_dtor(&dataset); + props_handled = 1; } if (ce->constructor) { @@ -1308,6 +1306,9 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags * single value is an array. Also we'd have to make that one * argument passed by reference. */ + if (!props_handled) { + zval_ptr_dtor(&dataset); + } zend_throw_exception(zend_ce_exception, "Parameter ctor_params must be an array", 0); return; } @@ -1320,7 +1321,14 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags fcc.object = Z_OBJ_P(return_value); if (zend_call_function(&fci, &fcc) == FAILURE) { + if (fci.params) { + efree(fci.params); + } + if (!props_handled) { + zval_ptr_dtor(&dataset); + } zend_throw_exception_ex(zend_ce_exception, 0, "Could not execute %s::%s()", ZSTR_VAL(ce->name), ZSTR_VAL(ce->constructor->common.function_name)); + return; } else { zval_ptr_dtor(&retval); } @@ -1328,7 +1336,16 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags efree(fci.params); } } else if (ctor_params) { + if (!props_handled) { + zval_ptr_dtor(&dataset); + } zend_throw_exception_ex(zend_ce_exception, 0, "Class %s does not have a constructor hence you cannot use ctor_params", ZSTR_VAL(ce->name)); + return; + } + + if (!props_handled) { + zend_merge_properties(return_value, Z_ARRVAL(dataset)); + zval_ptr_dtor(&dataset); } } } |
