Skip to content

Commit d9529fb

Browse files
committed
Create getter instead of making the property public
1 parent c4ce127 commit d9529fb

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed

ext/mysqli/mysqli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ PHP_MINIT_FUNCTION(mysqli)
568568
mysqli_exception_class_entry = zend_register_internal_class_ex(&cex, spl_ce_RuntimeException);
569569
mysqli_exception_class_entry->ce_flags |= ZEND_ACC_FINAL;
570570
zend_declare_property_long(mysqli_exception_class_entry, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED);
571-
zend_declare_property_string(mysqli_exception_class_entry, "sqlstate", sizeof("sqlstate")-1, "00000", ZEND_ACC_PUBLIC);
571+
zend_declare_property_string(mysqli_exception_class_entry, "sqlstate", sizeof("sqlstate")-1, "00000", ZEND_ACC_PROTECTED);
572572

573573
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_driver", mysqli_driver_class_entry, class_mysqli_driver_methods);
574574
ce = mysqli_driver_class_entry;

ext/mysqli/mysqli.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ public function next(): bool {}
519519

520520
final class mysqli_sql_exception extends RuntimeException
521521
{
522+
public function getSqlState(): string {}
522523
}
523524

524525
function mysqli_affected_rows(mysqli $mysql): int|string {}

ext/mysqli/mysqli_arginfo.h

Lines changed: 6 additions & 1 deletion
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: 04fabe8f7b61ccf36e8ed383396bd4b56e11dd25 */
2+
* Stub hash: ac7844bb479d2ddd81c5a172c8c3944470cdd697 */
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)
@@ -685,6 +685,9 @@ ZEND_END_ARG_INFO()
685685

686686
#define arginfo_class_mysqli_warning_next arginfo_mysqli_thread_safe
687687

688+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_mysqli_sql_exception_getSqlState, 0, 0, IS_STRING, 0)
689+
ZEND_END_ARG_INFO()
690+
688691

689692
ZEND_FUNCTION(mysqli_affected_rows);
690693
ZEND_FUNCTION(mysqli_autocommit);
@@ -810,6 +813,7 @@ ZEND_METHOD(mysqli_result, getIterator);
810813
ZEND_METHOD(mysqli_stmt, __construct);
811814
ZEND_METHOD(mysqli_warning, __construct);
812815
ZEND_METHOD(mysqli_warning, next);
816+
ZEND_METHOD(mysqli_sql_exception, getSqlState);
813817

814818

815819
static const zend_function_entry ext_functions[] = {
@@ -1057,5 +1061,6 @@ static const zend_function_entry class_mysqli_warning_methods[] = {
10571061

10581062

10591063
static const zend_function_entry class_mysqli_sql_exception_methods[] = {
1064+
ZEND_ME(mysqli_sql_exception, getSqlState, arginfo_class_mysqli_sql_exception_getSqlState, ZEND_ACC_PUBLIC)
10601065
ZEND_FE_END
10611066
};

ext/mysqli/mysqli_exception.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "php_mysqli_structs.h"
2727
#include "mysqli_priv.h"
2828
#include "zend_exceptions.h"
29+
#include "zend_string.h"
2930

3031
void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...)
3132
{
@@ -63,3 +64,17 @@ void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, .
6364

6465
zend_throw_exception_object(&sql_ex);
6566
}
67+
68+
PHP_METHOD(mysqli_sql_exception, getSqlState)
69+
{
70+
zval *prop;
71+
zval rv;
72+
73+
ZEND_PARSE_PARAMETERS_NONE();
74+
75+
prop = zend_read_property(mysqli_exception_class_entry, Z_OBJ_P(ZEND_THIS), "sqlstate", sizeof("sqlstate")-1, 1, &rv);
76+
ZVAL_DEREF(prop);
77+
zend_string *str = zval_get_string(prop);
78+
79+
RETURN_STR(str);
80+
}

ext/mysqli/php_mysqli_structs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ struct st_mysqli_warning {
121121
MYSQLI_WARNING *next;
122122
};
123123

124+
typedef struct st_mysqli_sql_exception MYSQLI_SQL_EXCEPTION;
125+
struct st_mysqli_sql_exception {
126+
zend_string *message;
127+
zend_string *sqlstate;
128+
int code;
129+
};
130+
124131
typedef struct _mysqli_property_entry {
125132
const char *pname;
126133
size_t pname_length;

ext/mysqli/tests/bugGH1.phpt renamed to ext/mysqli/tests/bugGH7746.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
1717
try {
1818
$link->query("stuff");
1919
} catch (mysqli_sql_exception $exception) {
20-
var_dump($exception->sqlstate);
20+
var_dump($exception->getSqlState());
2121
}
2222

2323
?>

0 commit comments

Comments
 (0)