[php-src] Issue #8985: Conditional definition

From: Date: Tue, 12 Jul 2022 19:28:57 +0000
Subject: [php-src] Issue #8985: Conditional definition
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241913@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8985 Author: punyflash ### Description ## Why it's necessary? There are quite a lot of cases when you want some variable, or more likely some array key, to be defined on some specific condition. Currently, in PHP, we achieve this doing like so: ```php $array = [ 'foo' => 'bar', 'bar' => null, ]; if (isset($baz)) { $array['baz'] = $baz; } ``` Every time I'm facing this case, my first thought is just to use null coalescing operator and set this annoying bar to be undefined. But sadly, there is no comfortable way to do so. ## How it would be nice to do? My dream (and hopefully someone else) to be able to do something like this in future PHP versions: ```php $array = [ 'foo' => 'bar', 'bar' => null, 'baz' => $baz ?? undefined ]; ``` Is it even possible?

« previous php.bugs (#241913) next »