Skip to content

Commit d3f8159

Browse files
committed
Fix code review
1 parent 53721f2 commit d3f8159

File tree

4 files changed

+15
-36
lines changed

4 files changed

+15
-36
lines changed

ext/mysqli/mysqli.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ zval *mysqli_read_property(zend_object *object, zend_string *name, int type, voi
303303

304304
obj = php_mysqli_fetch_object(object);
305305

306+
if (type == BP_VAR_IS && !obj->ptr) {
307+
return &EG(uninitialized_zval);
308+
}
309+
306310
if (obj->prop_handler != NULL) {
307311
hnd = zend_hash_find_ptr(obj->prop_handler, name);
308312
}
@@ -404,6 +408,7 @@ HashTable *mysqli_object_get_debug_info(zend_object *object, int *is_temp)
404408
ZEND_HASH_FOREACH_PTR(props, entry) {
405409
zval rv;
406410
zval *value;
411+
407412
value = mysqli_read_property(object, entry->name, BP_VAR_IS, 0, &rv);
408413
if (value != &EG(uninitialized_zval)) {
409414
zend_hash_add(retval, entry->name, value);

ext/mysqli/mysqli_nonapi.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ static int mysqlnd_zval_array_to_mysqlnd_array(zval *in_array, MYSQLND ***out_ar
731731
int i = 0, current = 0;
732732

733733
if (Z_TYPE_P(in_array) != IS_ARRAY) {
734-
return 0;
734+
return SUCCESS;
735735
}
736736
*out_array = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(in_array)) + 1, sizeof(MYSQLND *));
737737
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(in_array), elem) {
@@ -745,17 +745,17 @@ static int mysqlnd_zval_array_to_mysqlnd_array(zval *in_array, MYSQLND ***out_ar
745745
mysqli_object *intern = Z_MYSQLI_P(elem);
746746
if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {
747747
zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(intern->zo.ce->name));
748-
return -1;
748+
return FAILURE;
749749
}
750750
mysql = (MY_MYSQL*) my_res->ptr;
751751
if (MYSQLI_STATUS_VALID && my_res->status < MYSQLI_STATUS_VALID) {
752-
zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(intern->zo.ce->name));
753-
return -1;
752+
zend_throw_error(NULL, "%s object is not fully initialized", ZSTR_VAL(intern->zo.ce->name));
753+
return FAILURE;
754754
}
755755
(*out_array)[current++] = mysql->mysql;
756756
}
757757
} ZEND_HASH_FOREACH_END();
758-
return 0;
758+
return SUCCESS;
759759
}
760760
/* }}} */
761761

@@ -859,13 +859,13 @@ PHP_FUNCTION(mysqli_poll)
859859
}
860860

861861
if (r_array != NULL) {
862-
if (mysqlnd_zval_array_to_mysqlnd_array(r_array, &new_r_array) == -1) {
862+
if (mysqlnd_zval_array_to_mysqlnd_array(r_array, &new_r_array) == FAILURE) {
863863
efree(new_r_array);
864864
RETURN_THROWS();
865865
}
866866
}
867867
if (e_array != NULL) {
868-
if (mysqlnd_zval_array_to_mysqlnd_array(e_array, &new_e_array) == -1) {
868+
if (mysqlnd_zval_array_to_mysqlnd_array(e_array, &new_e_array) == FAILURE) {
869869
efree(new_e_array);
870870
RETURN_THROWS();
871871
}

ext/mysqli/tests/mysqli_real_connect.phpt

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ mysqli.allow_local_infile=1
111111
}
112112

113113
mysqli_close($link);
114-
try {
115-
@var_dump($link);
116-
} catch (Error $exception) {
117-
echo $exception->getMessage() . "\n";
118-
}
114+
var_dump($link);
119115

120116
if ($IS_MYSQLND) {
121117
ini_set('mysqli.default_host', 'p:' . $host);
@@ -159,19 +155,6 @@ mysqli.allow_local_infile=1
159155
--EXPECTF--
160156
Warning: mysqli_real_connect(): (%s/%d): Access denied for user '%s'@'%s' (using password: YES) in %s on line %d
161157
object(mysqli)#%d (%d) {
162-
["affected_rows"]=>
163-
bool(false)
164-
["client_info"]=>
165-
%s
166-
["client_version"]=>
167-
int(%d)
168-
["connect_errno"]=>
169-
int(%d)
170-
["connect_error"]=>
171-
NULL
172-
["error_list"]=>
173-
%s
174158
}
175159
mysqli object is already closed
176-
mysqli object is already closed
177160
done!

ext/mysqli/tests/mysqli_result_references.phpt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ require_once('skipifconnectfailure.inc');
6060
$references[$idx++] = &$res;
6161
mysqli_free_result($res);
6262

63-
try {
64-
@debug_zval_dump($references);
65-
} catch (Error $exception) {
66-
echo $exception->getMessage() . "\n";
67-
}
63+
debug_zval_dump($references);
6864

6965
if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1")) ||
7066
!($res = mysqli_use_result($link)))
@@ -134,14 +130,9 @@ array(7) refcount(2){
134130
&int(4)
135131
}
136132
[6]=>
137-
&object(mysqli_result)#%d (2) refcount(%d){
138-
["lengths"]=>
139-
bool(false)
140-
["type"]=>
141-
bool(false)
133+
&object(mysqli_result)#%d (0) refcount(%d){
142134
}
143135
}
144-
mysqli_result object is already closed
145136
array(1) refcount(2){
146137
[0]=>
147138
array(2) refcount(1){

0 commit comments

Comments
 (0)