Skip to content

Commit 98b8995

Browse files
committed
Handle strlen() in VM
1 parent 756f797 commit 98b8995

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Test null arg behavior for special functions
3+
--FILE--
4+
<?php
5+
6+
$null = null;
7+
var_dump(strlen($null));
8+
9+
?>
10+
--EXPECTF--
11+
Deprecated: strlen(): Passing null to argument of type string is deprecated in %s on line %d
12+
int(0)

Zend/tests/nullsafe_operator/013.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dump_error(fn() => array_key_exists('foo', $foo?->foo()));
3838

3939
?>
4040
--EXPECTF--
41-
Deprecated: {closure}(): Passing null to argument of type string is deprecated in %s on line %d
41+
Deprecated: strlen(): Passing null to argument of type string is deprecated in %s on line %d
4242
int(0)
4343
bool(true)
4444
bool(false)

Zend/zend_vm_def.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8310,6 +8310,16 @@ ZEND_VM_COLD_CONST_HANDLER(121, ZEND_STRLEN, CONST|TMPVAR|CV, ANY)
83108310
zend_string *str;
83118311
zval tmp;
83128312

8313+
if (UNEXPECTED(Z_TYPE_P(value) == IS_NULL)) {
8314+
zend_error(E_DEPRECATED,
8315+
"strlen(): Passing null to argument of type string is deprecated");
8316+
if (UNEXPECTED(EG(exception))) {
8317+
HANDLE_EXCEPTION();
8318+
}
8319+
ZVAL_LONG(EX_VAR(opline->result.var), 0);
8320+
break;
8321+
}
8322+
83138323
ZVAL_COPY(&tmp, value);
83148324
if (zend_parse_arg_str_weak(&tmp, &str)) {
83158325
ZVAL_LONG(EX_VAR(opline->result.var), ZSTR_LEN(str));

Zend/zend_vm_execute.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5286,6 +5286,16 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_STRLEN_SPEC_CONST
52865286
zend_string *str;
52875287
zval tmp;
52885288

5289+
if (UNEXPECTED(Z_TYPE_P(value) == IS_NULL)) {
5290+
zend_error(E_DEPRECATED,
5291+
"strlen(): Passing null to argument of type string is deprecated");
5292+
if (UNEXPECTED(EG(exception))) {
5293+
HANDLE_EXCEPTION();
5294+
}
5295+
ZVAL_LONG(EX_VAR(opline->result.var), 0);
5296+
break;
5297+
}
5298+
52895299
ZVAL_COPY(&tmp, value);
52905300
if (zend_parse_arg_str_weak(&tmp, &str)) {
52915301
ZVAL_LONG(EX_VAR(opline->result.var), ZSTR_LEN(str));
@@ -14459,6 +14469,16 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_STRLEN_SPEC_TMPVAR_HANDLER(ZEN
1445914469
zend_string *str;
1446014470
zval tmp;
1446114471

14472+
if (UNEXPECTED(Z_TYPE_P(value) == IS_NULL)) {
14473+
zend_error(E_DEPRECATED,
14474+
"strlen(): Passing null to argument of type string is deprecated");
14475+
if (UNEXPECTED(EG(exception))) {
14476+
HANDLE_EXCEPTION();
14477+
}
14478+
ZVAL_LONG(EX_VAR(opline->result.var), 0);
14479+
break;
14480+
}
14481+
1446214482
ZVAL_COPY(&tmp, value);
1446314483
if (zend_parse_arg_str_weak(&tmp, &str)) {
1446414484
ZVAL_LONG(EX_VAR(opline->result.var), ZSTR_LEN(str));
@@ -38546,6 +38566,16 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_STRLEN_SPEC_CV_HANDLER(ZEND_OP
3854638566
zend_string *str;
3854738567
zval tmp;
3854838568

38569+
if (UNEXPECTED(Z_TYPE_P(value) == IS_NULL)) {
38570+
zend_error(E_DEPRECATED,
38571+
"strlen(): Passing null to argument of type string is deprecated");
38572+
if (UNEXPECTED(EG(exception))) {
38573+
HANDLE_EXCEPTION();
38574+
}
38575+
ZVAL_LONG(EX_VAR(opline->result.var), 0);
38576+
break;
38577+
}
38578+
3854938579
ZVAL_COPY(&tmp, value);
3855038580
if (zend_parse_arg_str_weak(&tmp, &str)) {
3855138581
ZVAL_LONG(EX_VAR(opline->result.var), ZSTR_LEN(str));

0 commit comments

Comments
 (0)