class MyClass { // Class definition } $ref = new ReflectionClass('MyClass'); if($ref->isUserDefined()) { echo "MyClass is user-defined."; } else { echo "MyClass is not user-defined."; }
MyClass is user-defined.
$ref = new ReflectionClass('DateTime'); if($ref->isUserDefined()) { echo "DateTime is user-defined."; } else { echo "DateTime is not user-defined."; }
DateTime is not user-defined.In this example, we have created an instance of the ReflectionClass class for the DateTime class which is an internal class in PHP. We then used the isUserDefined() method to determine whether DateTime is user-defined or not and printed the output accordingly. Package/Library: The ReflectionClass class is a built-in class in PHP and does not belong to any external package or library.