Skip to content

Wiki ClsObj

Danijel Galić edited this page Jan 23, 2024 · 1 revision
abstract class \FireHub\Core\Support\LowLevel\ClsObj()

Important

This is an abstract class that cannot be instantiated directly.

### Class and object low-level proxy class

Class allows you to obtain information about classes and objects.

This class was created by Danijel Galić <danijel.galic@outlook.com>
Copyright: 2024 FireHub Web Application Framework
License: <https://opensource.org/licenses/OSL-3.0> OSL Open Source License version 3
Version: GIT: $Id$ Blob checksum.

Fully Qualified Class Name:  \FireHub\Core\Support\LowLevel\ClsObj
Source code:  view source code
Blame:  view blame
History:  view history

Methods

Type Name Title
public static methodExist ### Checks if the class method exists
public static propertyExist ### Checks if the object or class has a property
public static ofClass ### Checks whether the object or class is of a given type or subtype
public static subClassOf ### Checks if class has this class as one of its parents or implements it
public static methods ### Gets the class or object methods names
public static parentClass ### Retrieves the parent class name for an object or class
public static parents ### Return the parent classes of the given class
public static implements ### Return the interfaces which are implemented by the given class or interface
public static uses ### Return the traits used by the given class
public static ClsObj::methodExist(string|object $object_or_class, string $method):bool

Note

Using this function will use any registered autoloaders if the class is not already known.

### Checks if the class method exists

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object An object instance or a class name.
  • string $method - non-empty-string The method name.

Returns

  • bool - True if the method given by method has been defined for the given object_or_class, false otherwise.
final public static ClsObj::propertyExist(string|object $object_or_class, string $property):bool

Important

This method is marked as final.

Note

As opposed with isset(), ClsObj#propertyExist() returns true even if the property has the value null.> [!NOTE] This method cannot detect properties that are magically accessible using the __get magic method.> [!NOTE] Using this function will use any registered autoloaders if the class is not already known.

### Checks if the object or class has a property

This method checks if the given property exists in the specified class.

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object The class name or an object of the class to test for.
  • string $property - non-empty-string The name of the property.

Throws

  • \Error - If there was an error trying to get property.

Returns

  • bool - True if the property exists, false if it doesn't exist.
public static ClsObj::ofClass(string|object $object_or_class, string $class, bool $autoload = true):bool

### Checks whether the object or class is of a given type or subtype

Checks if the given $object_or_class is of this object type or has this object type as one of its supertypes.

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object A class name or an object instance.
  • string $class - The class or interface name.
  • bool $autoload = true - _[optional] Whether to allow this function to load the class automatically through the _autoload magic method.

Returns

  • bool - True if the object is of this object type or has this object type as one of its supertypes, false otherwise.
public static ClsObj::subClassOf(string|object $object_or_class, string $class, bool $autoload = true):bool

### Checks if class has this class as one of its parents or implements it

Checks if the given object_or_class has the class $class as one of its parents or implements it.

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object The tested class. No error is generated if the class does not exist.
  • string $class - The class or interface name.
  • bool $autoload = true - _[optional] Whether to allow this function to load the class automatically through the _autoload magic method.

Returns

  • bool - True if the object is of this object or lass type or has this object type as one of its supertypes, false otherwise.
final public static ClsObj::methods(string|object $object_or_class):array

Important

This method is marked as final.

Note

The result depends on the current scope.

### Gets the class or object methods names

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object The class name or an object instance.

Throws

  • \TypeError - If $object_or_class is not an object or a valid class name.

Returns

  • array - array Returns an array of method names defined for the class.
final public static ClsObj::parentClass(string|object $object_or_class):string|false

Important

This method is marked as final.

### Retrieves the parent class name for an object or class

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object The tested object or class name. This parameter is optional if called from the object's method.

Returns

  • string or false - class-string|false The name of the parent class for the class that $object_or_class is an instance or the name, or false if object_or_class doesn't have a parent.
final public static ClsObj::parents(string|object $object_or_class, bool $autoload = true):array

Important

This method is marked as final.

### Return the parent classes of the given class

This function returns an array with the name of the parent classes of the given object_or_class.

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object An object (class instance) or a string (class or interface name).
  • bool $autoload = true - _[optional] Whether to allow this function to load the class automatically through the _autoload magic method.

Throws

  • \Error - If $object_or_class does not exist and could not be loaded.

Returns

  • array - array<string, class-string> An array on success.
final public static ClsObj::implements(string|object $object_or_class, bool $autoload = true):array

Important

This method is marked as final.

### Return the interfaces which are implemented by the given class or interface

This function returns an array with the names of the interfaces that the given object_or_class and its parents implement.

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object An object (class instance) or a string (class or interface name).
  • bool $autoload = true - _[optional] Whether to allow this function to load the class automatically through the _autoload magic method.

Throws

  • \Error - If $object_or_class does not exist and could not be loaded.

Returns

  • array - array<string, class-string> An array.
final public static ClsObj::uses(string|object $object_or_class, bool $autoload = true):array

Important

This method is marked as final.

### Return the traits used by the given class

This function returns an array with the names of the traits that the given object_or_class uses. This does, however, not include any traits used by a parent class.

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object An object (class instance) or a string (class or interface name).
  • bool $autoload = true - _[optional] Whether to allow this function to load the class automatically through the _autoload magic method.

Throws

  • \Error - If $object_or_class does not exist and could not be loaded.

Returns

  • array - array<string, class-string> An array.
Clone this wiki locally