note 129613 added to function.class-exists
| From: | sb@firstvector.org | Date: | Wed, 26 Jun 2024 12:21:03 +0000 |
| Subject: | note 129613 added to function.class-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221394@lists.php.net to get a copy of this message | ||
Beware that
\class_exists() returns true for enums.
<?php
enum Test: int
{
case One = 1;
case Two = 2;
}
\var_dump(\class_exists(Test::class)); // bool(true)
?>
Having this in mind, the correct check for a class existence is:
<?php
function is_class_exist(string $class): bool
{
return \class_exists($class) && !\enum_exists($class);
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 168.224.160.14)
----
Manual Page -- https://php.net/manual/en/function.class-exists.php
Edit -- https://main.php.net/note/edit/129613
Del: integrated -- https://main.php.net/note/delete/129613/integrated
Del: useless -- https://main.php.net/note/delete/129613/useless
Del: bad code -- https://main.php.net/note/delete/129613/bad+code
Del: spam -- https://main.php.net/note/delete/129613/spam
Del: non-english -- https://main.php.net/note/delete/129613/non-english
Del: in docs -- https://main.php.net/note/delete/129613/in+docs
Del: other reasons-- https://main.php.net/note/delete/129613
Reject -- https://main.php.net/note/reject/129613
Search -- https://main.php.net/manage/user-notes.php