mirror of
https://github.com/php/php-src.git
synced 2026-04-14 11:32:11 +02:00
Merge branch 'PHP-8.1'
* PHP-8.1: Fix bug GH-7746 (mysqli_sql_exception->sqlstate is inaccessible)
This commit is contained in:
@@ -613,6 +613,8 @@ final class mysqli_warning
|
||||
final class mysqli_sql_exception extends RuntimeException
|
||||
{
|
||||
protected string $sqlstate = "00000";
|
||||
|
||||
public function getSqlState(): string {}
|
||||
}
|
||||
|
||||
/** @refcount 1 */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: e9f4dd04e7d01864c38033bcaf5e03b63e191deb */
|
||||
* Stub hash: 78662c05cd463735a8a4101c0357fd0d2698d48e */
|
||||
|
||||
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)
|
||||
@@ -720,6 +720,9 @@ ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_class_mysqli_warning_next arginfo_mysqli_thread_safe
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_mysqli_sql_exception_getSqlState, 0, 0, IS_STRING, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
|
||||
ZEND_FUNCTION(mysqli_affected_rows);
|
||||
ZEND_FUNCTION(mysqli_autocommit);
|
||||
@@ -842,6 +845,7 @@ ZEND_METHOD(mysqli_result, getIterator);
|
||||
ZEND_METHOD(mysqli_stmt, __construct);
|
||||
ZEND_METHOD(mysqli_warning, __construct);
|
||||
ZEND_METHOD(mysqli_warning, next);
|
||||
ZEND_METHOD(mysqli_sql_exception, getSqlState);
|
||||
|
||||
|
||||
static const zend_function_entry ext_functions[] = {
|
||||
@@ -1083,6 +1087,7 @@ static const zend_function_entry class_mysqli_warning_methods[] = {
|
||||
|
||||
|
||||
static const zend_function_entry class_mysqli_sql_exception_methods[] = {
|
||||
ZEND_ME(mysqli_sql_exception, getSqlState, arginfo_class_mysqli_sql_exception_getSqlState, ZEND_ACC_PUBLIC)
|
||||
ZEND_FE_END
|
||||
};
|
||||
|
||||
|
||||
@@ -63,3 +63,17 @@ void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, .
|
||||
|
||||
zend_throw_exception_object(&sql_ex);
|
||||
}
|
||||
|
||||
PHP_METHOD(mysqli_sql_exception, getSqlState)
|
||||
{
|
||||
zval *prop;
|
||||
zval rv;
|
||||
|
||||
ZEND_PARSE_PARAMETERS_NONE();
|
||||
|
||||
prop = zend_read_property(mysqli_exception_class_entry, Z_OBJ_P(ZEND_THIS), "sqlstate", sizeof("sqlstate")-1, 1, &rv);
|
||||
ZVAL_DEREF(prop);
|
||||
zend_string *str = zval_get_string(prop);
|
||||
|
||||
RETURN_STR(str);
|
||||
}
|
||||
|
||||
25
ext/mysqli/tests/gh7746.phpt
Normal file
25
ext/mysqli/tests/gh7746.phpt
Normal file
@@ -0,0 +1,25 @@
|
||||
--TEST--
|
||||
Bug #GH-7746 mysqli_sql_exception->sqlstate is inaccessible
|
||||
--EXTENSIONS--
|
||||
mysqli
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once "connect.inc";
|
||||
require_once 'skipifconnectfailure.inc';
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'connect.inc';
|
||||
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
|
||||
try {
|
||||
$link->query("stuff");
|
||||
} catch (mysqli_sql_exception $exception) {
|
||||
var_dump($exception->getSqlState());
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
string(5) "42000"
|
||||
Reference in New Issue
Block a user