[php-src] Issue #7825: Add nullsafe call and index access

From: Date: Fri, 15 Apr 2022 11:32:58 +0000
Subject: [php-src] Issue #7825: Add nullsafe call and index access
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-240994@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7825 Comment Author: iluuu1994 I've been doing some quick experimenting. There are a few things to consider: 1. How do we handle undefined indexes? There's similar confusion about $foo?->bar where bar does not exist. Some people expect nullsafe to suppress those errors. I don't think it makes sense there as undefined properties are not something you'd encounter often in correct code. With arrays and undefined indexes it's less clear. I'd imagine many people would think that []?.['foo'] would run without errors. 2. What about evaluation order of offset expressions? ```php echo $a[b()][c()]; // is equivalent to $b = b(); $c = c(); echo $a[$b][$c]; ``` Essentially, all offset expressions are evaluated before evaluating the actual offset access. ```php echo $a[b()]?[c()]; // should probably be equivalent to $b = b(); $tmp = $a[$b]; if ($tmp !== null) { $c = c(); $tmp = $tmp[$c]; } echo $tmp; ``` ?-> had similar issues that were only fixed later on. Over all, I'm not super convinced this is worthwhile, since ?? already does the job quite well.

« previous php.bugs (#240994) next »