Skip to content

Commit 05ba96f

Browse files
committed
Revert too strict string|int changes
1 parent 0ff1d89 commit 05ba96f

File tree

9 files changed

+103
-135
lines changed

9 files changed

+103
-135
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/bug72714.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Bug #72714 (_xml_startElementHandler() segmentation fault)
33
--SKIPIF--
44
<?php
55
if (!extension_loaded('xml')) die('skip xml extension not available');
6-
if (PHP_INT_SIZE != 8) die('skip 64-bit only');
76
?>
87
--FILE--
98
<?php

ext/xml/tests/xml_parser_set_option_variation3.phpt

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ Test xml_parser_set_option() function : usage variations
55
if (!extension_loaded("xml")) {
66
print "skip - XML extension not loaded";
77
}
8-
if (PHP_INT_SIZE != 8) {
9-
die('skip 64-bit only');
10-
}
118
?>
129
--FILE--
1310
<?php
@@ -80,12 +77,8 @@ $values = array(
8077
// loop through each element of the array for value
8178

8279
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-
}
80+
echo @"\nArg value $value \n";
81+
var_dump(xml_parser_set_option($parser, $option, $value));
8982
}
9083

9184
fclose($fp);
@@ -95,81 +88,83 @@ echo "Done";
9588
--EXPECTF--
9689
*** Testing xml_parser_set_option() : usage variations ***
9790

98-
Arg value 0
91+
Arg value 0
9992
bool(true)
10093

101-
Arg value 1
94+
Arg value 1
10295
bool(true)
10396

104-
Arg value 12345
97+
Arg value 12345
10598
bool(true)
10699

107-
Arg value -2345
100+
Arg value -2345
108101
bool(true)
109102

110-
Arg value 10.5
103+
Arg value 10.5
111104
bool(true)
112105

113-
Arg value -10.5
106+
Arg value -10.5
114107
bool(true)
115108

116-
Arg value 101234567000
109+
Arg value 101234567000
117110
bool(true)
118111

119-
Arg value 1.07654321E-9
112+
Arg value 1.07654321E-9
120113
bool(true)
121114

122-
Arg value 0.5
115+
Arg value 0.5
123116
bool(true)
124117

125-
Arg value Array
126-
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
118+
Arg value Array
119+
bool(true)
127120

128-
Arg value Array
129-
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
121+
Arg value Array
122+
bool(true)
130123

131-
Arg value Array
132-
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
124+
Arg value Array
125+
bool(true)
133126

134-
Arg value Array
135-
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
127+
Arg value Array
128+
bool(true)
136129

137-
Arg value Array
138-
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
130+
Arg value Array
131+
bool(true)
139132

140-
Arg value
133+
Arg value
141134
bool(true)
142135

143-
Arg value
136+
Arg value
144137
bool(true)
145138

146-
Arg value 1
139+
Arg value 1
147140
bool(true)
148141

149-
Arg value
142+
Arg value
150143
bool(true)
151144

152-
Arg value 1
145+
Arg value 1
153146
bool(true)
154147

155-
Arg value
148+
Arg value
156149
bool(true)
157150

158-
Arg value
159-
xml_parser_set_option(): Argument #3 ($value) must be of type int for the chosen option
151+
Arg value
152+
bool(true)
160153

161-
Arg value
162-
xml_parser_set_option(): Argument #3 ($value) must be of type int for the chosen option
154+
Arg value
155+
bool(true)
156+
157+
Arg value string
158+
bool(true)
163159

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

167-
Arg value string
168-
xml_parser_set_option(): Argument #3 ($value) must be of type int for the chosen option
163+
Arg value Some Ascii Data
169164

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

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

0 commit comments

Comments
 (0)