Skip to content

Commit d3a3e1a

Browse files
committed
Address review comments
1 parent 6ca5fd9 commit d3a3e1a

7 files changed

+20
-15
lines changed

Zend/tests/008.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Notice: Constant test const already defined in %s on line %d
4242
bool(false)
4343
bool(true)
4444
bool(true)
45-
define(): Argument #2 ($value) must be of type bool|int|float|string|array|resource|null, stdClass given
45+
define(): Argument #2 ($value) cannot be an object, stdClass given
4646
int(1)
4747
int(2)
4848
int(3)

Zend/tests/bug37811.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ try {
2929
?>
3030
--EXPECT--
3131
string(3) "Foo"
32-
define(): Argument #2 ($value) must be of type bool|int|float|string|array|resource|null, stdClass given
32+
define(): Argument #2 ($value) cannot be an object, stdClass given
3333
Undefined constant "Baz"

Zend/tests/constant_arrays.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,5 @@ array(1) {
101101
[0]=>
102102
int(7)
103103
}
104-
define(): Argument #2 ($value) must be of type bool|int|float|string|array|resource|null, stdClass given
104+
define(): Argument #2 ($value) cannot be an object, stdClass given
105105
define(): Argument #2 ($value) cannot be a recursive array

Zend/tests/constants_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ var_dump(foo);
2020

2121
?>
2222
--EXPECT--
23-
define(): Argument #2 ($value) must be of type bool|int|float|string|array|resource|null, stdClass given
23+
define(): Argument #2 ($value) cannot be an object, stdClass given
2424
Undefined constant "foo"
2525
resource(5) of type (stream)

Zend/zend_builtin_functions.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,7 @@ static int validate_constant_array_argument(HashTable *ht, int argument_number)
441441
}
442442
}
443443
} else if (Z_TYPE_P(val) != IS_STRING && Z_TYPE_P(val) != IS_RESOURCE) {
444-
zend_argument_type_error(2, "must be of type bool|int|float|string|array|resource|null, %s given",
445-
zend_zval_type_name(val)
446-
);
444+
zend_argument_type_error(argument_number, "cannot be an object, %s given", zend_zval_type_name(val));
447445
ret = 0;
448446
break;
449447
}
@@ -485,18 +483,26 @@ ZEND_FUNCTION(define)
485483
{
486484
zend_string *name;
487485
zval *val, val_free;
486+
zend_bool non_cs = 0;
488487
zend_constant c;
489488

490-
ZEND_PARSE_PARAMETERS_START(2, 2)
489+
ZEND_PARSE_PARAMETERS_START(2, 3)
491490
Z_PARAM_STR(name)
492491
Z_PARAM_ZVAL(val)
492+
Z_PARAM_OPTIONAL
493+
Z_PARAM_BOOL(non_cs)
493494
ZEND_PARSE_PARAMETERS_END();
494495

495496
if (zend_memnstr(ZSTR_VAL(name), "::", sizeof("::") - 1, ZSTR_VAL(name) + ZSTR_LEN(name))) {
496497
zend_argument_value_error(1, "cannot be a class constant");
497498
RETURN_THROWS();
498499
}
499500

501+
if (non_cs) {
502+
zend_error(E_WARNING, "define(): Declaration of case-insensitive constants is no longer supported");
503+
RETURN_FALSE;
504+
}
505+
500506
ZVAL_UNDEF(&val_free);
501507

502508
switch (Z_TYPE_P(val)) {
@@ -526,9 +532,7 @@ ZEND_FUNCTION(define)
526532
/* no break */
527533
default:
528534
zval_ptr_dtor(&val_free);
529-
zend_argument_type_error(2, "must be of type bool|int|float|string|array|resource|null, %s given",
530-
zend_zval_type_name(val)
531-
);
535+
zend_argument_type_error(2, "cannot be an object, %s given", zend_zval_type_name(val));
532536
RETURN_THROWS();
533537
}
534538

@@ -1453,8 +1457,8 @@ ZEND_FUNCTION(get_resources)
14531457
int id = zend_fetch_list_dtor_id(ZSTR_VAL(type));
14541458

14551459
if (id <= 0) {
1456-
zend_error(E_WARNING, "get_resources(): Unknown resource type \"%s\"", ZSTR_VAL(type));
1457-
RETURN_FALSE;
1460+
zend_argument_value_error(1, "must be a valid resource type");
1461+
RETURN_THROWS();
14581462
}
14591463

14601464
array_init(return_value);

Zend/zend_builtin_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function strncasecmp(string $string1, string $string2, int $length): int {}
2323
function error_reporting(?int $error_level = null): int {}
2424

2525
/** @param bool|int|float|string|array|resource|null $value */
26-
function define(string $constant_name, $value): bool {}
26+
function define(string $constant_name, $value, $case_insensitive = false): bool {}
2727

2828
function defined(string $constant_name): bool {}
2929

Zend/zend_builtin_functions_arginfo.h

Lines changed: 2 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: 8f915bc6d966efc2520aa706b9d00c72ead1954d */
2+
* Stub hash: 13ccb76ae84972dc12a26555e9d8652e58150378 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_version, 0, 0, IS_STRING, 0)
55
ZEND_END_ARG_INFO()
@@ -40,6 +40,7 @@ ZEND_END_ARG_INFO()
4040
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_define, 0, 2, _IS_BOOL, 0)
4141
ZEND_ARG_TYPE_INFO(0, constant_name, IS_STRING, 0)
4242
ZEND_ARG_INFO(0, value)
43+
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, case_insensitive, "false")
4344
ZEND_END_ARG_INFO()
4445

4546
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_defined, 0, 1, _IS_BOOL, 0)

0 commit comments

Comments
 (0)