note 127240 added to language.enumerations.listing
| From: | theking2 at king dot ma | Date: | Sat, 09 Jul 2022 08:57:34 +0000 |
| Subject: | note 127240 added to language.enumerations.listing | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218940@lists.php.net to get a copy of this message | ||
As ::cases() creates a Iteratable it is possible to use it in a foreach loop. In combination with
value backed enum this can result in very compact and very readable code:
<?php
/** Content Security Policy directives */
enum CspDirective: String {
case Default = "default-src";
case Image = "img-src";
case Font = "font-src";
case Script = "script-src";
case Style = "style-src";
}
/** list all CSP directives */
foreach( CspSource::cases() as $directive ) {
echo $directive-> value . PHP_EOL;
}
?>
Which results in:
default-src
img-src
font-src
script-src
style-src
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.12.131 (proxied: 83.97.81.249)
----
Manual Page -- https://php.net/manual/en/language.enumerations.listing.php
Edit -- https://main.php.net/note/edit/127240
Del: integrated -- https://main.php.net/note/delete/127240/integrated
Del: useless -- https://main.php.net/note/delete/127240/useless
Del: bad code -- https://main.php.net/note/delete/127240/bad+code
Del: spam -- https://main.php.net/note/delete/127240/spam
Del: non-english -- https://main.php.net/note/delete/127240/non-english
Del: in docs -- https://main.php.net/note/delete/127240/in+docs
Del: other reasons-- https://main.php.net/note/delete/127240
Reject -- https://main.php.net/note/reject/127240
Search -- https://main.php.net/manage/user-notes.php