From: Nikita Popov Date: Thu, 24 Sep 2020 14:51:47 +0000 (+0200) Subject: Make mysqli_warning constructor private X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8138ed73d73209024ad8500a4ab565b84259a1bf;p=php 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. --- diff --git a/ext/mysqli/mysqli.stub.php b/ext/mysqli/mysqli.stub.php index d3c32b61fb..5c7ae9bf98 100644 --- a/ext/mysqli/mysqli.stub.php +++ b/ext/mysqli/mysqli.stub.php @@ -511,7 +511,7 @@ class mysqli_stmt final class mysqli_warning { - protected function __construct(object $mysql) {} + private function __construct() {} public function next(): bool {} } diff --git a/ext/mysqli/mysqli_arginfo.h b/ext/mysqli/mysqli_arginfo.h index 48b07bb937..2666df942e 100644 --- a/ext/mysqli/mysqli_arginfo.h +++ b/ext/mysqli/mysqli_arginfo.h @@ -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) @@ -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 @@ -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 }; diff --git a/ext/mysqli/mysqli_warning.c b/ext/mysqli/mysqli_warning.c index 16cb0ebdfb..c99b3df5df 100644 --- a/ext/mysqli/mysqli_warning.c +++ b/ext/mysqli/mysqli_warning.c @@ -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; - } - - 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[] = { diff --git a/ext/mysqli/tests/mysqli_class_mysqli_warning.phpt b/ext/mysqli/tests/mysqli_class_mysqli_warning.phpt deleted file mode 100644 index 045d2b18c3..0000000000 --- a/ext/mysqli/tests/mysqli_class_mysqli_warning.phpt +++ /dev/null @@ -1,127 +0,0 @@ ---TEST-- -Interface of the class mysqli_warning - TODO ---SKIPIF-- - ---FILE-- -stmt_init(); - $warning = new mysqli_warning($stmt); - - $obj = new stdClass(); - $warning = new mysqli_warning($obj); - - include("table.inc"); - $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); - $res = $mysqli->query('INSERT INTO test(id, label) VALUES (1, "zz")'); - $warning = mysqli_get_warnings($mysqli); - - printf("Parent class:\n"); - var_dump(get_parent_class($warning)); - - printf("\nMethods:\n"); - $methods = get_class_methods($warning); - $expected_methods = array( - 'next' => true, - ); - - foreach ($methods as $k => $method) { - if (isset($expected_methods[$method])) { - unset($methods[$k]); - unset($expected_methods[$method]); - } - } - if (!empty($methods)) { - printf("Dumping list of unexpected methods.\n"); - var_dump($methods); - } - if (!empty($expected_methods)) { - printf("Dumping list of missing methods.\n"); - var_dump($expected_methods); - } - if (empty($methods) && empty($expected_methods)) - printf("ok\n"); - - printf("\nClass variables:\n"); - $variables = get_class_vars(get_class($mysqli)); - sort($variables); - foreach ($variables as $k => $var) - printf("%s\n", $var); - - printf("\nObject variables:\n"); - $variables = get_object_vars($mysqli); - foreach ($variables as $k => $var) - printf("%s\n", $var); - - printf("\nMagic, magic properties:\n"); - - assert('' === $warning->message); - printf("warning->message = '%s'\n", $warning->message); - - assert('' === $warning->sqlstate); - printf("warning->sqlstate= '%s'\n", $warning->sqlstate); - - assert(0 === $warning->errno); - printf("warning->errno = '%s'\n", $warning->errno); - - printf("\nAccess to undefined properties:\n"); - printf("warning->unknown = '%s'\n", @$warning->unknown); - - print "done!"; -?> ---CLEAN-- - ---EXPECTF-- -Warning: Wrong parameter count for mysqli_warning::mysqli_warning() in %s on line %d - -Warning: mysqli_warning::mysqli_warning(): Argument #1 must be of type object, null given in %s on line %d - -Warning: Wrong parameter count for mysqli_warning::mysqli_warning() in %s on line %d - -Warning: mysqli_warning::mysqli_warning(): mysqli object is already closed in %s on line %d -mysqli_stmt object is not fully initialized -mysqli_stmt object is not fully initialized - -Warning: mysqli_warning::mysqli_warning(): Invalid class argument in /home/nixnutz/php6_mysqlnd/ext/mysqli/tests/mysqli_class_mysqli_warning.php on line 19 - -Warning: mysqli_warning::mysqli_warning(): No warnings found in %s on line %d -Parent class: -bool(false) - -Methods: -ok - -Class variables: - -Object variables: - -Magic, magic properties: -warning->message = '' -warning->sqlstate= '' -warning->errno = '' - -Access to undefined properties: - -warning->unknown = '' -done!