note 127112 added to language.enumerations.basics
| From: | Andrzej at main dot php dot net | Date: | Wed, 18 May 2022 15:40:48 +0000 |
| Subject: | note 127112 added to language.enumerations.basics | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218489@lists.php.net to get a copy of this message | ||
Basic enumerations does not implement from() or tryFrom() methods, but it is possible to return the
corresponding Enum Case from variable using the constant() function.
<?php
enum Limit {
case Min;
case Max;
}
$value = 'Min';
$limit = constant("Limit::{$value}");
$limit === Limit::Min; // true
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.47 (proxied: 85.221.153.177)
----
Manual Page -- https://php.net/manual/en/language.enumerations.basics.php
Edit -- https://main.php.net/note/edit/127112
Del: integrated -- https://main.php.net/note/delete/127112/integrated
Del: useless -- https://main.php.net/note/delete/127112/useless
Del: bad code -- https://main.php.net/note/delete/127112/bad+code
Del: spam -- https://main.php.net/note/delete/127112/spam
Del: non-english -- https://main.php.net/note/delete/127112/non-english
Del: in docs -- https://main.php.net/note/delete/127112/in+docs
Del: other reasons-- https://main.php.net/note/delete/127112
Reject -- https://main.php.net/note/reject/127112
Search -- https://main.php.net/manage/user-notes.php