PHP class_uses() Function Last Updated : 26 Apr, 2023 Comments Improve Suggest changes Like Article Like Report The class_uses() function is an inbuilt function in PHP where the traits utilized by the given class, will be returned. Syntax: class_uses($object_or_class,$autoload = true): array|false Parameters: This function accepts the two parameters that are described below object_or_class: The name of the class or object passed in this parameter.autoload: This is an optional parameter for whether or not to automatically load the class file if it has not been loaded yet. The default is true. Return value: If the function is successfully executed it will return an array otherwise it will return "false". Example 1: The following code demonstrates the class_uses() function. PHP <?php trait MyTrait { public function hello() { echo "Hello, world!\n"; } } class MyClass { use MyTrait; } $traits = class_uses("MyClass"); echo "The following traits are used by MyClass:\n"; foreach ($traits as $trait) { echo "- $trait\n"; } ?> Output: The following traits are used by MyClass: - MyTrait Example 2: The following code demonstrates the class_uses() function. PHP <?php trait MyTrait1 { public function hello() { echo "Hello, world from Trait 1!\n"; } } trait MyTrait2 { public function goodbye() { echo "Goodbye, world from Trait 2!\n"; } } class MyClass { use MyTrait1, MyTrait2; } $traits = class_uses("MyClass"); echo "The following traits are used by MyClass:\n"; foreach ($traits as $trait) { echo "- $trait\n"; } ?> Output: The following traits are used by MyClass: - MyTrait1 - MyTrait2 Reference: https://www.php.net/manual/en/function.class-uses.php Comment More infoAdvertise with us Next Article PHP class_uses() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-SPL-Functions Similar Reads PHP | call_user_func() Function The call_user_func() is an inbuilt function in PHP which is used to call the callback given by the first parameter and passes the remaining parameters as argument. It is used to call the user-defined functions. Syntax: mixed call_user_func ( $function_name[, mixed $value1[, mixed $... ]]) Here, mixe 2 min read PHP | class_exists() Function The class_exists() function is an inbuilt function in PHP which is used to check whether the given class is defined or not. Syntax: bool class_exists( string $class_name, bool $autoload = TRUE ) Parameters: This function accept two parameters as mentioned above and described below: $class_name: It h 2 min read PHP strlen() Function The strlen() is a built-in function in PHP which returns the length of a given string.It calculates the length of the string including all the whitespaces and special characters. Syntax:strlen($string);Parameters: This parameter represents the string whose length is needed to be returned. Return Val 1 min read PHP fscanf() Function The fscanf() function is an inbuilt function in PHP that parses the file's input according to format, i.e., it accepts the input from a file that is associated with the stream & the input will be interpreted according to the specified format. This function is similar to sscanf() function. Any wh 2 min read PHP | time() Function The time() function is a built-in function in PHP which returns the current time measured in the number of seconds since the Unix Epoch. The number of seconds can be converted to the current date using date() function in PHP. Syntax: int time() Parameter: This function does not accepts any parameter 2 min read Like