Category
language
Problem
Nullsafe calls (?->) are a PHP 8 language feature with specific short-circuit semantics:
- if the receiver is
null, the entire chain evaluates to null without evaluating arguments or side effects
- if the receiver is non-null but not an object, Zend raises a type error consistent with normal
->
No open parity issue was found for the nullsafe operator.
php-src reference
Zend/zend_compile.c — AST nodes and opcode emission for nullsafe chains
Zend/zend_execute.c — runtime short-circuit behavior
Repro (failure today)
Save as repro_nullsafe.php:
<?php
class C { public function f($x) { echo "call\n"; return $x; } }
$c = null;
var_export($c?->f((function(){ echo "arg\n"; return 1; })()));
echo "\n";
$c = new C();
var_export($c?->f(2));
echo "\n";
Run:
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_nullsafe.php
# Zend expected:
# NULL
# call
# 2
php bin/vm.php repro_nullsafe.php
# today: parse/compile failure or wrong evaluation order
'
Scope (this repo)
- Compiler lowering for nullsafe property/method access and chaining
- VM execution: argument evaluation must be skipped when receiver is null
- Ensure correct interaction with
??, isset, and nested expressions
Done when
Links
Category
languageProblem
Nullsafe calls (
?->) are a PHP 8 language feature with specific short-circuit semantics:null, the entire chain evaluates tonullwithout evaluating arguments or side effects->No open parity issue was found for the nullsafe operator.
php-src reference
Zend/zend_compile.c— AST nodes and opcode emission for nullsafe chainsZend/zend_execute.c— runtime short-circuit behaviorRepro (failure today)
Save as
repro_nullsafe.php:Run:
Scope (this repo)
??,isset, and nested expressionsDone when
repro_nullsafe.phpoutput matches Zend on VMLinks