Skip to content

Commit 8138ed7

Browse files
committed
Make mysqli_warning constructor private
The constructor was already effectively inaccessible (protected on a final class). This just makes it more obvious and removes the implementation in favor of directly throwing. Per the removed test, this was an unfinished feature, and I don't think it makes a lot of sense to finish it -- the mysqli_stmt::get_warnings() interface makes more sense than direct construction. Closes GH-6208.
1 parent 02dc9ce commit 8138ed7

File tree

4 files changed

+6
-190
lines changed

4 files changed

+6
-190
lines changed

ext/mysqli/mysqli.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ public function get_result() {}
511511

512512
final class mysqli_warning
513513
{
514-
protected function __construct(object $mysql) {}
514+
private function __construct() {}
515515

516516
public function next(): bool {}
517517
}

ext/mysqli/mysqli_arginfo.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 54e11efaf9b7b020e27cb0b7a30098af93e1c6f9 */
2+
* Stub hash: 7687edcf18fa03c0ae95ac4b3d32c196790ba65e */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_affected_rows, 0, 1, MAY_BE_LONG|MAY_BE_STRING)
55
ZEND_ARG_OBJ_INFO(0, mysql, mysqli, 0)
@@ -688,9 +688,7 @@ ZEND_END_ARG_INFO()
688688
#define arginfo_class_mysqli_stmt_get_result arginfo_class_mysqli_get_connection_stats
689689
#endif
690690

691-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_warning___construct, 0, 0, 1)
692-
ZEND_ARG_TYPE_INFO(0, mysql, IS_OBJECT, 0)
693-
ZEND_END_ARG_INFO()
691+
#define arginfo_class_mysqli_warning___construct arginfo_class_mysqli_character_set_name
694692

695693
#define arginfo_class_mysqli_warning_next arginfo_mysqli_thread_safe
696694

@@ -1059,7 +1057,7 @@ static const zend_function_entry class_mysqli_stmt_methods[] = {
10591057

10601058

10611059
static const zend_function_entry class_mysqli_warning_methods[] = {
1062-
ZEND_ME(mysqli_warning, __construct, arginfo_class_mysqli_warning___construct, ZEND_ACC_PROTECTED)
1060+
ZEND_ME(mysqli_warning, __construct, arginfo_class_mysqli_warning___construct, ZEND_ACC_PRIVATE)
10631061
ZEND_ME(mysqli_warning, next, arginfo_class_mysqli_warning_next, ZEND_ACC_PUBLIC)
10641062
ZEND_FE_END
10651063
};

ext/mysqli/mysqli_warning.c

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -254,67 +254,12 @@ static int mysqli_warning_errno(mysqli_object *obj, zval *retval, zend_bool quie
254254
}
255255
/* }}} */
256256

257-
/* {{{ mysqli_warning_construct(object obj) */
258257
PHP_METHOD(mysqli_warning, __construct)
259258
{
260-
zval *z;
261-
mysqli_object *obj;
262-
#ifndef MYSQLI_USE_MYSQLND
263-
MYSQL *hdl;
264-
#endif
265-
MYSQLI_WARNING *w;
266-
MYSQLI_RESOURCE *mysqli_resource;
267-
268-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &z) == FAILURE) {
269-
RETURN_THROWS();
270-
}
271-
obj = Z_MYSQLI_P(z);
272-
273-
if (obj->zo.ce == mysqli_link_class_entry) {
274-
MY_MYSQL *mysql;
275-
MYSQLI_FETCH_RESOURCE_CONN(mysql, z, MYSQLI_STATUS_VALID);
276-
if (mysql_warning_count(mysql->mysql)) {
277-
#ifndef MYSQLI_USE_MYSQLND
278-
w = php_get_warnings(mysql->mysql);
279-
#else
280-
w = php_get_warnings(mysql->mysql->data);
281-
#endif
282-
} else {
283-
php_error_docref(NULL, E_WARNING, "No warnings found");
284-
RETURN_FALSE;
285-
}
286-
} else if (obj->zo.ce == mysqli_stmt_class_entry) {
287-
MY_STMT *stmt;
288-
MYSQLI_FETCH_RESOURCE_STMT(stmt, z, MYSQLI_STATUS_VALID);
289-
#ifndef MYSQLI_USE_MYSQLND
290-
hdl = mysqli_stmt_get_connection(stmt->stmt);
291-
if (mysql_warning_count(hdl)) {
292-
w = php_get_warnings(hdl);
293-
#else
294-
if (mysqlnd_stmt_warning_count(stmt->stmt)) {
295-
w = php_get_warnings(mysqli_stmt_get_connection(stmt->stmt));
296-
#endif
297-
} else {
298-
php_error_docref(NULL, E_WARNING, "No warnings found");
299-
RETURN_FALSE;
300-
}
301-
} else {
302-
php_error_docref(NULL, E_WARNING, "Invalid class argument");
303-
RETURN_FALSE;
304-
}
305-
306-
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
307-
mysqli_resource->ptr = mysqli_resource->info = (void *)w;
308-
mysqli_resource->status = MYSQLI_STATUS_VALID;
309-
310-
if (!getThis() || !instanceof_function(Z_OBJCE_P(getThis()), mysqli_warning_class_entry)) {
311-
MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_warning_class_entry);
312-
} else {
313-
(Z_MYSQLI_P(getThis()))->ptr = mysqli_resource;
314-
}
259+
ZEND_PARSE_PARAMETERS_NONE();
315260

261+
zend_throw_error(NULL, "Cannot directly construct mysqli_warning");
316262
}
317-
/* }}} */
318263

319264
/* {{{ mysqli_warning_property_entries */
320265
const mysqli_property_entry mysqli_warning_property_entries[] = {

ext/mysqli/tests/mysqli_class_mysqli_warning.phpt

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)