|
|
|
|
@ -20,6 +20,18 @@ function boolSource(): bool |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function assignmentSource(): int |
|
|
|
|
{ |
|
|
|
|
echo "assignment-called\n"; |
|
|
|
|
return 73; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function exceptionSource(): int |
|
|
|
|
{ |
|
|
|
|
echo "exception-called\n"; |
|
|
|
|
throw new RuntimeException('folded-exception'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function main(): void |
|
|
|
|
{ |
|
|
|
|
if (is_int(intSource())) { |
|
|
|
|
@ -32,6 +44,20 @@ function main(): void |
|
|
|
|
// Plain variables still fold without extra evaluation. |
|
|
|
|
$n = 7; |
|
|
|
|
echo is_int($n) ? "var-int\n" : "var-not-int\n"; |
|
|
|
|
|
|
|
|
|
// The folded operand must run exactly once and preserve its result. |
|
|
|
|
$assigned = 0; |
|
|
|
|
echo is_int($assigned = assignmentSource()) ? "assigned-int\n" : "assigned-not-int\n"; |
|
|
|
|
echo "assigned-value=", $assigned, "\n"; |
|
|
|
|
|
|
|
|
|
// Folding the predicate must not suppress an exception from its operand. |
|
|
|
|
try { |
|
|
|
|
if (is_int(exceptionSource())) { |
|
|
|
|
echo "exception-not-thrown\n"; |
|
|
|
|
} |
|
|
|
|
} catch (RuntimeException $e) { |
|
|
|
|
echo "caught=", $e->getMessage(), "\n"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
?> |
|
|
|
|
--EXPECT-- |
|
|
|
|
@ -42,3 +68,8 @@ is-float |
|
|
|
|
bool-called |
|
|
|
|
is-bool |
|
|
|
|
var-int |
|
|
|
|
assignment-called |
|
|
|
|
assigned-int |
|
|
|
|
assigned-value=73 |
|
|
|
|
exception-called |
|
|
|
|
caught=folded-exception |
|
|
|
|
|