note 124362 deleted from language.operators.comparison by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 17:46:48 +0000 |
| Subject: | note 124362 deleted from language.operators.comparison by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217876@lists.php.net to get a copy of this message | ||
Note Submitter: azz
----
Keep in mind that ?: operator is NOT fully equal to empty()
?: can't check non-existent array index (as describe here https://www.php.net/manual/ru/language.operators.comparison.php#92685)
and vars
Check this:
<?php
ini_set('error_reporting', E_ALL);
$t = [];
var_dump(!isset($t['z']) || $t['z'] == FALSE); // true, this that empty() do
var_dump(empty($t['z'])); // true
var_dump(isset($t['z'])); // false
$v1 = $t['z'] ?: false; // Notice: Undefined index: z
$v2 = $t['z'] ?? false; // silent!
var_dump($v1); // false
var_dump($v2); // false
var_dump(!isset($non_existent_var) || $non_existent_var == FALSE); // true, this that empty() do
var_dump(empty($non_existent_var)); // true
var_dump(isset($non_existent_var)); // false
$v1 = $non_existent_var ?: false; // Notice: Undefined variable: non_existent_var
$v2 = $non_existent_var ?? false; // silent!
var_dump($v1); // false
var_dump($v2); // false