note 128979 added to function.is-bool

From: Date: Tue, 24 Oct 2023 11:41:34 +0000
Subject: note 128979 added to function.is-bool
Groups: php.notes 
Request: Send a blank email to php-notes+get-220936@lists.php.net to get a copy of this message
Since PHP 8.0.0, it's more flexible to use a match() structure (e.g. for translations into another language), with all benefits of strict comparisons (===): <?php function to_bool(int|bool|string|null $value): bool|null { return match(is_string($value) ? strtolower(trim($value)) : $value) { 1, TRUE, '1', 'true', 'on', 'yes', 'y' => TRUE, 0, FALSE, '0', 'false', 'off', 'no', 'n' => FALSE, default => NULL, }; } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 2a01:e0a:199:abf0:43::) ---- Manual Page -- https://php.net/manual/en/function.is-bool.php Edit -- https://main.php.net/note/edit/128979 Del: integrated -- https://main.php.net/note/delete/128979/integrated Del: useless -- https://main.php.net/note/delete/128979/useless Del: bad code -- https://main.php.net/note/delete/128979/bad+code Del: spam -- https://main.php.net/note/delete/128979/spam Del: non-english -- https://main.php.net/note/delete/128979/non-english Del: in docs -- https://main.php.net/note/delete/128979/in+docs Del: other reasons-- https://main.php.net/note/delete/128979 Reject -- https://main.php.net/note/reject/128979 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220936) next »