You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inconsistency between null safe operator and property fetch with null coalesce #8661
Warning: Undefined variable $a in /in/bgVKX on line 3
Warning: Undefined variable $a in /in/bgVKX on line 4
Warning: Undefined variable $a in /in/bgVKX on line 7
Warning: Attempt to read property "foo" on null in /in/bgVKX on line 7
But I expected this output instead:
Warning: Undefined variable $a in /in/bgVKX on line 3
Warning: Undefined variable $a in /in/bgVKX on line 7
Warning: Attempt to read property "foo" on null in /in/bgVKX on line 7
I think line 4 should not report a warning because the undefined var $a is handled by null coalescing operator like in line 8.
I believe it is a bug, because the inconsistency between line 4 and 5 (null coalesce vs isset), line 4 and line 8 (null safe vs non null safe) is hard to expect.
I agree. JMP_NULL currently always calls ZVAL_UNDEFINED_OP1(), even if compiled through zend_compile_coalesce(). It would make sense to avoid the undefined variable error here. This requires passing the BP type in the JMP_NULL opcode through extended_value. As extensions might depend on that value, I'm not sure if it makes more sense to only patch for PHP 8.2.
Activity
damianwadley commentedon May 31, 2022
Agreed that both line 4's
$a?->foo ?? ''and line 8's$a->foo ?? ''should behave the same.cmb69 commentedon May 31, 2022
I tend to agree, but maybe @iluuu1994 can clarify.
iluuu1994 commentedon May 31, 2022
I agree.
JMP_NULLcurrently always callsZVAL_UNDEFINED_OP1(), even if compiled throughzend_compile_coalesce(). It would make sense to avoid the undefined variable error here. This requires passing the BP type in theJMP_NULLopcode throughextended_value. As extensions might depend on that value, I'm not sure if it makes more sense to only patch for PHP 8.2.Fix phpGH-8661: Nullsafe in coalesce triggers undefined variable warning