doFoldSsaType folded a statically type-known is_int()/is_float()/ is_bool() call to the literal `true`, discarding the argument entirely. With `function f(): int`, `if (is_int(f()))` compiled to `if (true)` and f() was never invoked — its side effects silently vanished. Fold to a bare `true` only for plain variables and scalar literals; for any other argument emit `((void)(expr), true)` so the operand is still evaluated, mirroring how genIsNull already handles native scalar operands.master
parent
b493ac79c5
commit
e019f21550
2 changed files with 54 additions and 1 deletions
@ -0,0 +1,44 @@ |
||||
--TEST-- |
||||
Folded is_int/is_float/is_bool must keep evaluating side-effect arguments |
||||
--FILE-- |
||||
<?php |
||||
function intSource(): int |
||||
{ |
||||
echo "int-called\n"; |
||||
return 42; |
||||
} |
||||
|
||||
function floatSource(): float |
||||
{ |
||||
echo "float-called\n"; |
||||
return 1.5; |
||||
} |
||||
|
||||
function boolSource(): bool |
||||
{ |
||||
echo "bool-called\n"; |
||||
return true; |
||||
} |
||||
|
||||
function main(): void |
||||
{ |
||||
if (is_int(intSource())) { |
||||
echo "is-int\n"; |
||||
} |
||||
echo is_float(floatSource()) ? "is-float\n" : "not-float\n"; |
||||
$r = is_bool(boolSource()); |
||||
echo $r ? "is-bool\n" : "not-bool\n"; |
||||
|
||||
// Plain variables still fold without extra evaluation. |
||||
$n = 7; |
||||
echo is_int($n) ? "var-int\n" : "var-not-int\n"; |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
int-called |
||||
is-int |
||||
float-called |
||||
is-float |
||||
bool-called |
||||
is-bool |
||||
var-int |
||||
Loading…
Reference in new issue