Skip to content

Commit c6a712d

Browse files
committed
Fix stuffs
1 parent 307b242 commit c6a712d

10 files changed

+59
-130
lines changed

Zend/zend_API.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,23 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
15801580
#define Z_PARAM_OBJECT_OR_NULL(dest) \
15811581
Z_PARAM_OBJECT_EX(dest, 1, 0)
15821582

1583+
#define Z_PARAM_OBJ_EX2(dest, check_null, deref, separate) \
1584+
Z_PARAM_PROLOGUE(deref, separate); \
1585+
if (UNEXPECTED(!zend_parse_arg_obj(_arg, &dest, NULL, check_null))) { \
1586+
_expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
1587+
_error_code = ZPP_ERROR_WRONG_ARG; \
1588+
break; \
1589+
}
1590+
1591+
#define Z_PARAM_OBJ_EX(dest, check_null, separate) \
1592+
Z_PARAM_OBJ_EX2(dest, check_null, separate, separate)
1593+
1594+
#define Z_PARAM_OBJ(dest) \
1595+
Z_PARAM_OBJ_EX(dest, 0, 0)
1596+
1597+
#define Z_PARAM_OBJ_OR_NULL(dest) \
1598+
Z_PARAM_OBJ_EX(dest, 1, 0)
1599+
15831600
/* old "O" */
15841601
#define Z_PARAM_OBJECT_OF_CLASS_EX2(dest, _ce, check_null, deref, separate) \
15851602
Z_PARAM_PROLOGUE(deref, separate); \
@@ -1955,6 +1972,19 @@ static zend_always_inline bool zend_parse_arg_object(zval *arg, zval **dest, zen
19551972
return 1;
19561973
}
19571974

1975+
static zend_always_inline bool zend_parse_arg_obj(zval *arg, zend_object **dest, zend_class_entry *ce, bool check_null)
1976+
{
1977+
if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) &&
1978+
(!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0))) {
1979+
*dest = Z_OBJ_P(arg);
1980+
} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1981+
*dest = NULL;
1982+
} else {
1983+
return 0;
1984+
}
1985+
return 1;
1986+
}
1987+
19581988
static zend_always_inline bool zend_parse_arg_resource(zval *arg, zval **dest, bool check_null)
19591989
{
19601990
if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) {

ext/ldap/ldap.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
14451445
Z_PARAM_LONG(attrsonly)
14461446
Z_PARAM_LONG(sizelimit)
14471447
Z_PARAM_LONG(timelimit)
1448+
Z_PARAM_LONG(deref)
14481449
Z_PARAM_ARRAY_EX(serverctrls, 0, 1)
14491450
ZEND_PARSE_PARAMETERS_END();
14501451

@@ -1523,10 +1524,6 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15231524
} else {
15241525
nfilters = 0; /* this means string, not array */
15251526
ldap_filter = zend_string_copy(filter_str);
1526-
if (EG(exception)) {
1527-
ret = 0;
1528-
goto cleanup;
1529-
}
15301527
}
15311528

15321529
lds = safe_emalloc(nlinks, sizeof(ldap_linkdata), 0);
@@ -1597,23 +1594,21 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15971594
efree(lds);
15981595
efree(rcs);
15991596
} else {
1600-
ldap_filter = zval_get_string(filter);
1601-
if (EG(exception)) {
1597+
ld = (ldap_linkdata *) zend_fetch_resource_ex(link, "ldap link", le_link);
1598+
if (ld == NULL) {
16021599
ret = 0;
16031600
goto cleanup;
16041601
}
16051602

1606-
ldap_base_dn = zval_get_string(base_dn);
1607-
if (EG(exception)) {
1608-
ret = 0;
1609-
goto cleanup;
1603+
if (!base_dn_str) {
1604+
zend_argument_type_error(2, "must be of type string when argument #1 ($link_identifier) is a resource");
16101605
}
1606+
ldap_base_dn = zend_string_copy(base_dn_str);
16111607

1612-
ld = (ldap_linkdata *) zend_fetch_resource_ex(link, "ldap link", le_link);
1613-
if (ld == NULL) {
1614-
ret = 0;
1615-
goto cleanup;
1608+
if (!filter_str) {
1609+
zend_argument_type_error(3, "must be of type string when argument #1 ($link_identifier) is a resource");
16161610
}
1611+
ldap_filter = zend_string_copy(filter_str);
16171612

16181613
if (argcount > 8) {
16191614
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls);

ext/reflection/php_reflection.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3684,38 +3684,35 @@ ZEND_METHOD(ReflectionClassConstant, getAttributes)
36843684
/* {{{ reflection_class_object_ctor */
36853685
static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_object)
36863686
{
3687-
zval *argument;
36883687
zval *object;
3688+
zend_string *arg_class = NULL;
3689+
zend_object *arg_obj;
36893690
reflection_object *intern;
36903691
zend_class_entry *ce;
36913692

36923693
if (is_object) {
36933694
ZEND_PARSE_PARAMETERS_START(1, 1)
3694-
Z_PARAM_OBJECT(argument)
3695+
Z_PARAM_OBJ(arg_obj)
36953696
ZEND_PARSE_PARAMETERS_END();
36963697
} else {
36973698
ZEND_PARSE_PARAMETERS_START(1, 1)
3698-
Z_PARAM_ZVAL(argument)
3699+
Z_PARAM_STR_OR_OBJ(arg_class, arg_obj)
36993700
ZEND_PARSE_PARAMETERS_END();
37003701
}
37013702

37023703
object = ZEND_THIS;
37033704
intern = Z_REFLECTION_P(object);
37043705

3705-
if (Z_TYPE_P(argument) == IS_OBJECT) {
3706-
ZVAL_STR_COPY(reflection_prop_name(object), Z_OBJCE_P(argument)->name);
3707-
intern->ptr = Z_OBJCE_P(argument);
3706+
if (arg_obj) {
3707+
ZVAL_STR_COPY(reflection_prop_name(object), arg_obj->ce->name);
3708+
intern->ptr = arg_obj->ce;
37083709
if (is_object) {
3709-
ZVAL_COPY(&intern->obj, argument);
3710+
ZVAL_OBJ_COPY(&intern->obj, arg_obj);
37103711
}
37113712
} else {
3712-
if (!try_convert_to_string(argument)) {
3713-
RETURN_THROWS();
3714-
}
3715-
3716-
if ((ce = zend_lookup_class(Z_STR_P(argument))) == NULL) {
3713+
if ((ce = zend_lookup_class(arg_class)) == NULL) {
37173714
if (!EG(exception)) {
3718-
zend_throw_exception_ex(reflection_exception_ptr, -1, "Class \"%s\" does not exist", Z_STRVAL_P(argument));
3715+
zend_throw_exception_ex(reflection_exception_ptr, -1, "Class \"%s\" does not exist", ZSTR_VAL(arg_class));
37193716
}
37203717
RETURN_THROWS();
37213718
}

ext/reflection/php_reflection.stub.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ class ReflectionClass implements Reflector
202202
{
203203
final private function __clone() {}
204204

205-
/** @param object|string $objectOrClass */
206-
public function __construct($objectOrClass) {}
205+
public function __construct(object|string $objectOrClass) {}
207206

208207
public function __toString(): string {}
209208

ext/reflection/php_reflection_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: beaf79270ab56d2e87a301a4a5d4444b2cc520d8 */
2+
* Stub hash: 1311fc5c498d6f16afb5a18aee2d60e72048174f */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0)
@@ -150,7 +150,7 @@ ZEND_END_ARG_INFO()
150150
#define arginfo_class_ReflectionClass___clone arginfo_class_ReflectionFunctionAbstract___clone
151151

152152
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass___construct, 0, 0, 1)
153-
ZEND_ARG_INFO(0, objectOrClass)
153+
ZEND_ARG_TYPE_MASK(0, objectOrClass, MAY_BE_OBJECT|MAY_BE_STRING, NULL)
154154
ZEND_END_ARG_INFO()
155155

156156
#define arginfo_class_ReflectionClass___toString arginfo_class_ReflectionFunction___toString

ext/reflection/tests/ReflectionClass_constructor_002.phpt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ try {
2828

2929
try {
3030
var_dump(new ReflectionClass(array(1,2,3)));
31-
} catch (Exception $e) {
31+
} catch (TypeError $e) {
3232
echo $e->getMessage() . "\n";
3333
}
3434

@@ -45,13 +45,11 @@ try {
4545
}
4646

4747
?>
48-
--EXPECTF--
48+
--EXPECT--
4949
ReflectionClass::__construct() expects exactly 1 parameter, 0 given
5050
Class "" does not exist
5151
Class "1" does not exist
5252
Class "1" does not exist
53-
54-
Warning: Array to string conversion in %s on line %d
55-
Class "Array" does not exist
53+
ReflectionClass::__construct(): Argument #1 ($objectOrClass) must be of type object|string, array given
5654
ReflectionClass::__construct() expects exactly 1 parameter, 2 given
5755
Class "X" does not exist

ext/reflection/tests/ReflectionClass_toString_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String
3737
Method [ <internal:Reflection, ctor> public method __construct ] {
3838

3939
- Parameters [1] {
40-
Parameter #0 [ <required> $objectOrClass ]
40+
Parameter #0 [ <required> object|string $objectOrClass ]
4141
}
4242
}
4343

ext/snmp/snmp.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,6 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
10861086
zend_bool use_orignames = 0, suffix_keys = 0;
10871087
zend_long timeout = SNMP_DEFAULT_TIMEOUT;
10881088
zend_long retries = SNMP_DEFAULT_RETRIES;
1089-
int argc = ZEND_NUM_ARGS();
10901089
struct objid_query objid_query;
10911090
php_snmp_session *session;
10921091
int session_less_mode = (getThis() == NULL);

ext/snmp/tests/reflection.phpt

Lines changed: 0 additions & 89 deletions
This file was deleted.

ext/standard/streamsfuncs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -998,19 +998,19 @@ PHP_FUNCTION(stream_context_set_option)
998998
if (options) {
999999
if (optionname) {
10001000
zend_argument_value_error(3, "must be null when argument #2 ($wrapper_or_options) is an array");
1001-
RETURN_THROWS();
1001+
RETURN_THROWS();
10021002
}
10031003

10041004
if (zvalue) {
10051005
zend_argument_value_error(4, "cannot be provided when argument #2 ($wrapper_or_options) is an array");
1006-
RETURN_THROWS();
1006+
RETURN_THROWS();
10071007
}
10081008

10091009
RETURN_BOOL(parse_context_options(context, options) == SUCCESS);
10101010
} else {
10111011
if (!optionname) {
10121012
zend_argument_value_error(3, "cannot be null when argument #2 ($wrapper_or_options) is a string");
1013-
RETURN_THROWS();
1013+
RETURN_THROWS();
10141014
}
10151015

10161016
RETURN_BOOL(php_stream_context_set_option(context, ZSTR_VAL(wrappername), optionname, zvalue) == SUCCESS);

0 commit comments

Comments
 (0)