Skip to content

Make mysqli_warning constructor private #6208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/mysqli/mysqli.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public function get_result() {}

final class mysqli_warning
{
protected function __construct(object $mysql) {}
private function __construct() {}

public function next(): bool {}
}
Expand Down
8 changes: 3 additions & 5 deletions ext/mysqli/mysqli_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 54e11efaf9b7b020e27cb0b7a30098af93e1c6f9 */
* Stub hash: 7687edcf18fa03c0ae95ac4b3d32c196790ba65e */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_affected_rows, 0, 1, MAY_BE_LONG|MAY_BE_STRING)
ZEND_ARG_OBJ_INFO(0, mysql, mysqli, 0)
Expand Down Expand Up @@ -688,9 +688,7 @@ ZEND_END_ARG_INFO()
#define arginfo_class_mysqli_stmt_get_result arginfo_class_mysqli_get_connection_stats
#endif

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_warning___construct, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, mysql, IS_OBJECT, 0)
ZEND_END_ARG_INFO()
#define arginfo_class_mysqli_warning___construct arginfo_class_mysqli_character_set_name

#define arginfo_class_mysqli_warning_next arginfo_mysqli_thread_safe

Expand Down Expand Up @@ -1059,7 +1057,7 @@ static const zend_function_entry class_mysqli_stmt_methods[] = {


static const zend_function_entry class_mysqli_warning_methods[] = {
ZEND_ME(mysqli_warning, __construct, arginfo_class_mysqli_warning___construct, ZEND_ACC_PROTECTED)
ZEND_ME(mysqli_warning, __construct, arginfo_class_mysqli_warning___construct, ZEND_ACC_PRIVATE)
ZEND_ME(mysqli_warning, next, arginfo_class_mysqli_warning_next, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
Expand Down
59 changes: 2 additions & 57 deletions ext/mysqli/mysqli_warning.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,67 +254,12 @@ static int mysqli_warning_errno(mysqli_object *obj, zval *retval, zend_bool quie
}
/* }}} */

/* {{{ mysqli_warning_construct(object obj) */
PHP_METHOD(mysqli_warning, __construct)
{
zval *z;
mysqli_object *obj;
#ifndef MYSQLI_USE_MYSQLND
MYSQL *hdl;
#endif
MYSQLI_WARNING *w;
MYSQLI_RESOURCE *mysqli_resource;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &z) == FAILURE) {
RETURN_THROWS();
}
obj = Z_MYSQLI_P(z);

if (obj->zo.ce == mysqli_link_class_entry) {
MY_MYSQL *mysql;
MYSQLI_FETCH_RESOURCE_CONN(mysql, z, MYSQLI_STATUS_VALID);
if (mysql_warning_count(mysql->mysql)) {
#ifndef MYSQLI_USE_MYSQLND
w = php_get_warnings(mysql->mysql);
#else
w = php_get_warnings(mysql->mysql->data);
#endif
} else {
php_error_docref(NULL, E_WARNING, "No warnings found");
RETURN_FALSE;
}
} else if (obj->zo.ce == mysqli_stmt_class_entry) {
MY_STMT *stmt;
MYSQLI_FETCH_RESOURCE_STMT(stmt, z, MYSQLI_STATUS_VALID);
#ifndef MYSQLI_USE_MYSQLND
hdl = mysqli_stmt_get_connection(stmt->stmt);
if (mysql_warning_count(hdl)) {
w = php_get_warnings(hdl);
#else
if (mysqlnd_stmt_warning_count(stmt->stmt)) {
w = php_get_warnings(mysqli_stmt_get_connection(stmt->stmt));
#endif
} else {
php_error_docref(NULL, E_WARNING, "No warnings found");
RETURN_FALSE;
}
} else {
php_error_docref(NULL, E_WARNING, "Invalid class argument");
RETURN_FALSE;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning + return false is how I got here ... a constructor is not allowed to return false.

}

mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
mysqli_resource->ptr = mysqli_resource->info = (void *)w;
mysqli_resource->status = MYSQLI_STATUS_VALID;

if (!getThis() || !instanceof_function(Z_OBJCE_P(getThis()), mysqli_warning_class_entry)) {
MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_warning_class_entry);
} else {
(Z_MYSQLI_P(getThis()))->ptr = mysqli_resource;
}
ZEND_PARSE_PARAMETERS_NONE();

zend_throw_error(NULL, "Cannot directly construct mysqli_warning");
}
/* }}} */

/* {{{ mysqli_warning_property_entries */
const mysqli_property_entry mysqli_warning_property_entries[] = {
Expand Down
127 changes: 0 additions & 127 deletions ext/mysqli/tests/mysqli_class_mysqli_warning.phpt

This file was deleted.