Skip to content

Commit 44a5c7a

Browse files
committed
Revert too strict string|int changes
1 parent 0ff1d89 commit 44a5c7a

File tree

8 files changed

+78
-106
lines changed

8 files changed

+78
-106
lines changed

ext/mysqli/mysqli.stub.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,18 @@ public function select_db(string $database) {}
237237
public function set_charset(string $charset) {}
238238

239239
/**
240+
* @param string|int $value
240241
* @return bool
241242
* @alias mysqli_options
242243
*/
243-
public function options(int $option, string|int $value) {}
244+
public function options(int $option, $value) {}
244245

245246
/**
247+
* @param string|int $value
246248
* @return bool
247249
* @alias mysqli_options
248250
*/
249-
public function set_opt(int $option, string|int $value) {}
251+
public function set_opt(int $option, $value) {}
250252

251253
/**
252254
* @return bool
@@ -628,7 +630,8 @@ function mysqli_num_fields(mysqli_result $mysql_result): int {}
628630

629631
function mysqli_num_rows(mysqli_result $mysqli_result): int|string {}
630632

631-
function mysqli_options(mysqli $mysqli_link, int $option, string|int $value): bool {}
633+
/** @param string|int $value */
634+
function mysqli_options(mysqli $mysqli_link, int $option, $value): bool {}
632635

633636
function mysqli_ping(mysqli $mysqli_link): bool {}
634637

@@ -749,5 +752,8 @@ function mysqli_refresh(mysqli $mysqli_link, int $options): bool {}
749752
/** @alias mysqli_real_escape_string */
750753
function mysqli_escape_string(mysqli $mysqli_link, string $string_to_escape): string {}
751754

752-
/** @alias mysqli_options */
753-
function mysqli_set_opt(mysqli $mysqli_link, int $option, string|int $value): bool {}
755+
/**
756+
* @param string|int $value
757+
* @alias mysqli_options
758+
*/
759+
function mysqli_set_opt(mysqli $mysqli_link, int $option, $value): bool {}

ext/mysqli/mysqli_api.c

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,26 +1675,16 @@ static int mysqli_options_get_option_zval_type(int option)
16751675
PHP_FUNCTION(mysqli_options)
16761676
{
16771677
MY_MYSQL *mysql;
1678-
zval *mysql_link = getThis();
1679-
zend_string *mysql_value_str;
1680-
zend_long mysql_value_long;
1678+
zval *mysql_link = NULL;
1679+
zval *mysql_value;
16811680
zend_long mysql_option;
1681+
unsigned int l_value;
16821682
zend_long ret;
16831683
int expected_type;
16841684

1685-
if (mysql_link) {
1686-
ZEND_PARSE_PARAMETERS_START(2, 2)
1687-
Z_PARAM_LONG(mysql_option)
1688-
Z_PARAM_STR_OR_LONG(mysql_value_str, mysql_value_long)
1689-
ZEND_PARSE_PARAMETERS_END();
1690-
} else {
1691-
ZEND_PARSE_PARAMETERS_START(3, 3)
1692-
Z_PARAM_OBJECT_OF_CLASS(mysql_link, mysqli_link_class_entry)
1693-
Z_PARAM_LONG(mysql_option)
1694-
Z_PARAM_STR_OR_LONG(mysql_value_str, mysql_value_long)
1695-
ZEND_PARSE_PARAMETERS_END();
1685+
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Olz", &mysql_link, mysqli_link_class_entry, &mysql_option, &mysql_value) == FAILURE) {
1686+
RETURN_THROWS();
16961687
}
1697-
16981688
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_INITIALIZED);
16991689

17001690
#ifndef MYSQLI_USE_MYSQLND
@@ -1705,34 +1695,31 @@ PHP_FUNCTION(mysqli_options)
17051695
}
17061696
#endif
17071697
expected_type = mysqli_options_get_option_zval_type(mysql_option);
1708-
if (expected_type == IS_STRING) {
1709-
bool is_long_arg = 0;
1710-
if (!mysql_value_str) {
1711-
mysql_value_str = zend_long_to_str(mysql_value_long);
1712-
is_long_arg = 1;
1713-
}
1714-
ret = mysql_options(mysql->mysql, mysql_option, ZSTR_VAL(mysql_value_str));
1715-
1716-
if (is_long_arg) {
1717-
zend_string_release(mysql_value_str);
1718-
}
1719-
} else if (expected_type == IS_LONG) {
1720-
if (mysql_value_str) {
1721-
double rv;
1722-
zend_long lv;
1723-
zend_uchar type;
1724-
1725-
type = is_numeric_string(ZSTR_VAL(mysql_value_str), ZSTR_LEN(mysql_value_str), &lv, &rv, 0);
1726-
if (type == IS_LONG) {
1727-
mysql_value_long = lv;
1728-
} else {
1729-
zend_argument_type_error(getThis() ? 1 : 2, "must be a numeric string for the chosen option");
1730-
RETURN_THROWS();
1731-
}
1698+
if (expected_type != Z_TYPE_P(mysql_value)) {
1699+
switch (expected_type) {
1700+
case IS_STRING:
1701+
if (!try_convert_to_string(mysql_value)) {
1702+
RETURN_THROWS();
1703+
}
1704+
break;
1705+
case IS_LONG:
1706+
convert_to_long_ex(mysql_value);
1707+
break;
1708+
default:
1709+
break;
17321710
}
1733-
ret = mysql_options(mysql->mysql, mysql_option, (char *) &mysql_value_long);
1734-
} else {
1735-
ret = 1;
1711+
}
1712+
switch (expected_type) {
1713+
case IS_STRING:
1714+
ret = mysql_options(mysql->mysql, mysql_option, Z_STRVAL_P(mysql_value));
1715+
break;
1716+
case IS_LONG:
1717+
l_value = Z_LVAL_P(mysql_value);
1718+
ret = mysql_options(mysql->mysql, mysql_option, (char *)&l_value);
1719+
break;
1720+
default:
1721+
ret = 1;
1722+
break;
17361723
}
17371724

17381725
RETURN_BOOL(!ret);

ext/mysqli/mysqli_arginfo.h

Lines changed: 3 additions & 3 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: 5695d494cc9a1f780e65c525c47e047780bf80f1 */
2+
* Stub hash: a8626c7c42e4d117b08df7f42a7523f60f357b82 */
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_link, mysqli, 0)
@@ -208,7 +208,7 @@ ZEND_END_ARG_INFO()
208208
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_options, 0, 3, _IS_BOOL, 0)
209209
ZEND_ARG_OBJ_INFO(0, mysqli_link, mysqli, 0)
210210
ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0)
211-
ZEND_ARG_TYPE_MASK(0, value, MAY_BE_STRING|MAY_BE_LONG, NULL)
211+
ZEND_ARG_INFO(0, value)
212212
ZEND_END_ARG_INFO()
213213

214214
#define arginfo_mysqli_ping arginfo_mysqli_more_results
@@ -545,7 +545,7 @@ ZEND_END_ARG_INFO()
545545

546546
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_options, 0, 0, 2)
547547
ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0)
548-
ZEND_ARG_TYPE_MASK(0, value, MAY_BE_STRING|MAY_BE_LONG, NULL)
548+
ZEND_ARG_INFO(0, value)
549549
ZEND_END_ARG_INFO()
550550

551551
#define arginfo_class_mysqli_set_opt arginfo_class_mysqli_options

ext/mysqli/tests/mysqli_options.phpt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ require_once('skipifconnectfailure.inc');
3838
var_dump("MYSQLI_READ_DEFAULT_FILE", mysqli_options($link, MYSQLI_READ_DEFAULT_FILE, 'extra_my.cnf'));
3939
var_dump("MYSQLI_OPT_CONNECT_TIMEOUT", mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 10));
4040
var_dump("MYSQLI_OPT_LOCAL_INFILE", mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, 1));
41-
try {
42-
var_dump("MYSQLI_INIT_COMMAND");
43-
mysqli_options($link, MYSQLI_INIT_COMMAND, array('SET AUTOCOMMIT=0', 'SET AUTOCOMMIT=1'));
44-
} catch (TypeError $exception) {
45-
echo $exception->getMessage() . "\n";
46-
}
41+
var_dump("MYSQLI_INIT_COMMAND", mysqli_options($link, MYSQLI_INIT_COMMAND, array('SET AUTOCOMMIT=0', 'SET AUTOCOMMIT=1')));
4742

4843
if (!$link2 = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
4944
printf("[006] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
@@ -112,7 +107,10 @@ bool(true)
112107
%s(23) "MYSQLI_OPT_LOCAL_INFILE"
113108
bool(true)
114109
%s(19) "MYSQLI_INIT_COMMAND"
115-
mysqli_options(): Argument #3 ($value) must be of type string|int, array given
110+
111+
Warning: Array to string conversion in %s on line %d
112+
%s(19) "MYSQLI_INIT_COMMAND"
113+
bool(true)
116114
%s(25) "MYSQLI_READ_DEFAULT_GROUP"
117115
bool(true)
118116
%s(24) "MYSQLI_READ_DEFAULT_FILE"

ext/xml/tests/xml_parser_set_option_variation3.phpt

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,8 @@ $values = array(
8080
// loop through each element of the array for value
8181

8282
foreach($values as $value) {
83-
echo @"\nArg value $value \n";
84-
try {
85-
var_dump(xml_parser_set_option($parser, $option, $value));
86-
} catch (TypeError $exception) {
87-
echo $exception->getMessage() . "\n";
88-
}
83+
echo @"\nArg value $value \n";
84+
var_dump(xml_parser_set_option($parser, $option, $value));
8985
}
9086

9187
fclose($fp);
@@ -123,19 +119,19 @@ Arg value 0.5
123119
bool(true)
124120

125121
Arg value Array
126-
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
122+
bool(true)
127123

128124
Arg value Array
129-
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
125+
bool(true)
130126

131127
Arg value Array
132-
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
128+
bool(true)
133129

134130
Arg value Array
135-
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
131+
bool(true)
136132

137133
Arg value Array
138-
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
134+
bool(true)
139135

140136
Arg value
141137
bool(true)
@@ -156,20 +152,22 @@ Arg value
156152
bool(true)
157153

158154
Arg value
159-
xml_parser_set_option(): Argument #3 ($value) must be of type int for the chosen option
155+
bool(true)
160156

161157
Arg value
162-
xml_parser_set_option(): Argument #3 ($value) must be of type int for the chosen option
158+
bool(true)
163159

164160
Arg value string
165-
xml_parser_set_option(): Argument #3 ($value) must be of type int for the chosen option
161+
bool(true)
166162

167163
Arg value string
168-
xml_parser_set_option(): Argument #3 ($value) must be of type int for the chosen option
164+
bool(true)
169165

170166
Arg value Some Ascii Data
171-
xml_parser_set_option(): Argument #3 ($value) must be of type int for the chosen option
167+
168+
Notice: Object of class aClass could not be converted to int in %s on line %d
169+
bool(true)
172170

173171
Arg value Resource id %s
174-
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, resource given
172+
bool(true)
175173
Done

ext/xml/xml.c

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,58 +1412,40 @@ PHP_FUNCTION(xml_parser_free)
14121412
PHP_FUNCTION(xml_parser_set_option)
14131413
{
14141414
xml_parser *parser;
1415-
zval *pind;
1416-
zend_long opt, val_long;
1417-
zend_string *val_str;
1415+
zval *pind, *val;
1416+
zend_long opt;
14181417

1419-
ZEND_PARSE_PARAMETERS_START(3, 3)
1420-
Z_PARAM_OBJECT_OF_CLASS(pind, xml_parser_ce)
1421-
Z_PARAM_LONG(opt)
1422-
Z_PARAM_STR_OR_LONG(val_str, val_long)
1423-
ZEND_PARSE_PARAMETERS_END();
1418+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olz", &pind, xml_parser_ce, &opt, &val) == FAILURE) {
1419+
RETURN_THROWS();
1420+
}
14241421

14251422
parser = Z_XMLPARSER_P(pind);
14261423
switch (opt) {
14271424
case PHP_XML_OPTION_CASE_FOLDING:
1428-
if (val_str) {
1429-
zend_argument_type_error(3, "must be of type int for the chosen option");
1430-
RETURN_THROWS();
1431-
}
1432-
1433-
parser->case_folding = val_long;
1425+
parser->case_folding = zval_get_long(val);
14341426
break;
14351427
case PHP_XML_OPTION_SKIP_TAGSTART:
1436-
if (val_str) {
1437-
zend_argument_type_error(3, "must be of type int for the chosen option");
1438-
RETURN_THROWS();
1439-
}
1440-
1441-
parser->toffset = val_long;
1428+
parser->toffset = zval_get_long(val);
14421429
if (parser->toffset < 0) {
14431430
php_error_docref(NULL, E_WARNING, "tagstart ignored, because it is out of range");
14441431
parser->toffset = 0;
14451432
}
14461433
break;
14471434
case PHP_XML_OPTION_SKIP_WHITE:
1448-
if (val_str) {
1449-
zend_argument_type_error(3, "must be of type int for the chosen option");
1450-
RETURN_THROWS();
1451-
}
1452-
1453-
parser->skipwhite = val_long;
1435+
parser->skipwhite = zval_get_long(val);
14541436
break;
14551437
case PHP_XML_OPTION_TARGET_ENCODING: {
14561438
const xml_encoding *enc;
1457-
if (!val_str) {
1458-
zend_argument_type_error(3, "must be of type string for the chosen option");
1439+
if (!try_convert_to_string(val)) {
14591440
RETURN_THROWS();
14601441
}
14611442

1462-
enc = xml_get_encoding((XML_Char*) ZSTR_VAL(val_str));
1443+
enc = xml_get_encoding((XML_Char*)Z_STRVAL_P(val));
14631444
if (enc == NULL) {
14641445
zend_argument_value_error(3, "is not a supported target encoding");
14651446
RETURN_THROWS();
14661447
}
1448+
14671449
parser->target_encoding = enc->name;
14681450
break;
14691451
}

ext/xml/xml.stub.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ function xml_get_current_byte_index(XmlParser $parser): int {}
5858

5959
function xml_parser_free(XmlParser $parser): bool {}
6060

61-
function xml_parser_set_option(XmlParser $parser, int $option, string|int $value): bool {}
61+
/** @param string|int $value */
62+
function xml_parser_set_option(XmlParser $parser, int $option, $value): bool {}
6263

6364
function xml_parser_get_option(XmlParser $parser, int $option): string|int {}
6465

ext/xml/xml_arginfo.h

Lines changed: 2 additions & 2 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: adc99bbb801c9b3ebd69e8967f7a2f74782763aa */
2+
* Stub hash: b3c718c2aeba9a9c05b6cb281fd7ccaa3791d34e */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_xml_parser_create, 0, 0, XmlParser, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null")
@@ -74,7 +74,7 @@ ZEND_END_ARG_INFO()
7474
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_parser_set_option, 0, 3, _IS_BOOL, 0)
7575
ZEND_ARG_OBJ_INFO(0, parser, XmlParser, 0)
7676
ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0)
77-
ZEND_ARG_TYPE_MASK(0, value, MAY_BE_STRING|MAY_BE_LONG, NULL)
77+
ZEND_ARG_INFO(0, value)
7878
ZEND_END_ARG_INFO()
7979

8080
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_xml_parser_get_option, 0, 2, MAY_BE_STRING|MAY_BE_LONG)

0 commit comments

Comments
 (0)