note 130415 added to backedenum.tryfrom
| From: | gssj85@gmail.com | Date: | Fri, 11 Jul 2025 13:41:38 +0000 |
| Subject: | note 130415 added to backedenum.tryfrom | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-222269@lists.php.net to get a copy of this message | ||
I use tryFrom when I don't want an exception to be thrown, when I don't expect the arg
passed will always be valid.
This will return null:
MyEnum::tryFrom($variableThatCanBeNull ?? '')
While this will throw an exception:
MyEnum::from($variableThatCanBeNull ?? '')
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 2804:7f4:c0c2:1b32:36d5:44ce:71f5:4dee)
----
Manual Page -- https://php.net/manual/en/backedenum.tryfrom.php
Edit -- https://main.php.net/note/edit/130415
Del: integrated -- https://main.php.net/note/delete/130415/integrated
Del: useless -- https://main.php.net/note/delete/130415/useless
Del: bad code -- https://main.php.net/note/delete/130415/bad+code
Del: spam -- https://main.php.net/note/delete/130415/spam
Del: non-english -- https://main.php.net/note/delete/130415/non-english
Del: in docs -- https://main.php.net/note/delete/130415/in+docs
Del: other reasons-- https://main.php.net/note/delete/130415
Reject -- https://main.php.net/note/reject/130415
Search -- https://main.php.net/manage/user-notes.php