Skip to content

Commit 993be4b

Browse files
committed
Fix STR_OR_OBJ_OF_TYPE stringable handling
1 parent 213494f commit 993be4b

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

Zend/tests/str_or_obj_of_class_zpp.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ if (!extension_loaded('zend-test')) die('skip zend-test extension not loaded');
88
<?php
99

1010
class Foo {}
11+
class ToString {
12+
public function __toString() {
13+
return "ToString";
14+
}
15+
}
1116

1217
var_dump(zend_string_or_stdclass("string"));
1318
var_dump(zend_string_or_stdclass(1));
1419
var_dump(zend_string_or_stdclass(null));
1520
var_dump(zend_string_or_stdclass(new stdClass()));
21+
var_dump(zend_string_or_stdclass(new ToString()));
1622

1723
try {
1824
zend_string_or_stdclass([]);
@@ -30,6 +36,7 @@ var_dump(zend_string_or_stdclass_or_null("string"));
3036
var_dump(zend_string_or_stdclass_or_null(1));
3137
var_dump(zend_string_or_stdclass_or_null(null));
3238
var_dump(zend_string_or_stdclass_or_null(new stdClass()));
39+
var_dump(zend_string_or_stdclass_or_null(new ToString()));
3340

3441
try {
3542
zend_string_or_stdclass_or_null([]);
@@ -50,12 +57,14 @@ string(1) "1"
5057
string(0) ""
5158
object(stdClass)#1 (0) {
5259
}
60+
string(8) "ToString"
5361
zend_string_or_stdclass(): Argument #1 ($param) must be of type stdClass|string, array given
5462
zend_string_or_stdclass(): Argument #1 ($param) must be of type stdClass|string, Foo given
5563
string(6) "string"
5664
string(1) "1"
5765
NULL
5866
object(stdClass)#1 (0) {
5967
}
68+
string(8) "ToString"
6069
zend_string_or_stdclass_or_null(): Argument #1 ($param) must be of type stdClass|string|null, array given
6170
zend_string_or_stdclass_or_null(): Argument #1 ($param) must be of type stdClass|string|null, Foo given

Zend/zend_API.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,24 +2014,15 @@ static zend_always_inline int zend_parse_arg_str_or_obj(
20142014
zval *arg, zend_string **destination_string, zend_object **destination_object, zend_class_entry *base_ce, int allow_null
20152015
) {
20162016
if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
2017-
if (base_ce && UNEXPECTED(!instanceof_function(Z_OBJCE_P(arg), base_ce))) {
2018-
return 0;
2017+
if (!base_ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), base_ce))) {
2018+
*destination_string = NULL;
2019+
*destination_object = Z_OBJ_P(arg);
2020+
return 1;
20192021
}
2020-
2021-
*destination_string = NULL;
2022-
*destination_object = Z_OBJ_P(arg);
2023-
} else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
2024-
*destination_string = Z_STR_P(arg);
2025-
*destination_object = NULL;
2026-
} else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2027-
*destination_string = NULL;
2028-
*destination_object = NULL;
2029-
} else {
2030-
*destination_object = NULL;
2031-
return zend_parse_arg_str_slow(arg, destination_string);
20322022
}
20332023

2034-
return 1;
2024+
*destination_object = NULL;
2025+
return zend_parse_arg_str(arg, destination_string, allow_null);
20352026
}
20362027

20372028
END_EXTERN_C()

0 commit comments

Comments
 (0)