note 127992 added to language.operators.logical

From: Date: Thu, 08 Dec 2022 01:39:00 +0000
Subject: note 127992 added to language.operators.logical
Groups: php.notes 
Request: Send a blank email to php-notes+get-219948@lists.php.net to get a copy of this message
In PHP, the || operator only ever returns a boolean. For a chainable assignment operator, use the ?: "Elvis" operator. JavaScript: let a = false; let b = false; let c = true; let d = false; let e = a || b || c || d; // e === c <?PHP $a = false; $b = false; $c = true; $d = false; $e = $a ?: $b ?: $c ?: $d; // $e === $c ?> Credit to @egst and others for the insight. This is merely a rewording for (formerly) lost JavaScript devs like myself. ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.175 (proxied: 65.154.183.242) ---- Manual Page -- https://php.net/manual/en/language.operators.logical.php Edit -- https://main.php.net/note/edit/127992 Del: integrated -- https://main.php.net/note/delete/127992/integrated Del: useless -- https://main.php.net/note/delete/127992/useless Del: bad code -- https://main.php.net/note/delete/127992/bad+code Del: spam -- https://main.php.net/note/delete/127992/spam Del: non-english -- https://main.php.net/note/delete/127992/non-english Del: in docs -- https://main.php.net/note/delete/127992/in+docs Del: other reasons-- https://main.php.net/note/delete/127992 Reject -- https://main.php.net/note/reject/127992 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#219948) next »