trait_exists()
trait_exists() — Checks if the trait exists.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.4.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
trait_exists(string $trait, bool $autoload = true): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $trait | string | Name of the trait to check |
| $autoload | bool | Whether to autoload if not already loaded. |
Return value
Returns true if trait exists, and false otherwise.
Example
The PHP manual ships no example for trait_exists(); the signature and the parameter table above are the contract.
All PHP 8.5 built-in functions
Reference card built from the PHP manual page trait_exists() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.