Skip to content

Commit

Permalink
Init STRLEN result when deprecation promoted to exception
Browse files Browse the repository at this point in the history
Move the result initialization before HANDLE_EXCEPTION(), the
actual value doesn't matter.

This fixes one of the issues report in bug #81190.
  • Loading branch information
nikic committed Jul 1, 2021
1 parent 36cb48c commit 353f963
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
17 changes: 17 additions & 0 deletions Zend/tests/strlen_deprecation_to_exception.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
strlen() null deprecation warning promoted to exception
--FILE--
<?php

set_error_handler(function($_, $msg) {
throw new Exception($msg);
});
try {
strlen(null);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
strlen(): Passing null to parameter #1 ($string) of type string is deprecated
2 changes: 1 addition & 1 deletion Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -8368,10 +8368,10 @@ ZEND_VM_COLD_CONST_HANDLER(121, ZEND_STRLEN, CONST|TMPVAR|CV, ANY)
if (UNEXPECTED(Z_TYPE_P(value) == IS_NULL)) {
zend_error(E_DEPRECATED,
"strlen(): Passing null to parameter #1 ($string) of type string is deprecated");
ZVAL_LONG(EX_VAR(opline->result.var), 0);
if (UNEXPECTED(EG(exception))) {
HANDLE_EXCEPTION();
}
ZVAL_LONG(EX_VAR(opline->result.var), 0);
break;
}

Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_vm_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -5461,10 +5461,10 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_STRLEN_SPEC_CONST
if (UNEXPECTED(Z_TYPE_P(value) == IS_NULL)) {
zend_error(E_DEPRECATED,
"strlen(): Passing null to parameter #1 ($string) of type string is deprecated");
ZVAL_LONG(EX_VAR(opline->result.var), 0);
if (UNEXPECTED(EG(exception))) {
HANDLE_EXCEPTION();
}
ZVAL_LONG(EX_VAR(opline->result.var), 0);
break;
}

Expand Down Expand Up @@ -14648,10 +14648,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_STRLEN_SPEC_TMPVAR_HANDLER(ZEN
if (UNEXPECTED(Z_TYPE_P(value) == IS_NULL)) {
zend_error(E_DEPRECATED,
"strlen(): Passing null to parameter #1 ($string) of type string is deprecated");
ZVAL_LONG(EX_VAR(opline->result.var), 0);
if (UNEXPECTED(EG(exception))) {
HANDLE_EXCEPTION();
}
ZVAL_LONG(EX_VAR(opline->result.var), 0);
break;
}

Expand Down Expand Up @@ -38691,10 +38691,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_STRLEN_SPEC_CV_HANDLER(ZEND_OP
if (UNEXPECTED(Z_TYPE_P(value) == IS_NULL)) {
zend_error(E_DEPRECATED,
"strlen(): Passing null to parameter #1 ($string) of type string is deprecated");
ZVAL_LONG(EX_VAR(opline->result.var), 0);
if (UNEXPECTED(EG(exception))) {
HANDLE_EXCEPTION();
}
ZVAL_LONG(EX_VAR(opline->result.var), 0);
break;
}

Expand Down

0 comments on commit 353f963

Please sign in to comment.