(PHP 7, PHP 8)
ReflectionNamedType::isBuiltin — Checks if it is a built-in type
Checks if the type is a built-in type in PHP. A built-in type is any type that is not a class, interface, or trait.
This function has no parameters.
Example #1 ReflectionNamedType::isBuiltin() example
<?php
class SomeClass {}
function someFunction(string $param, SomeClass $param2, stdClass $param3) {}
$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams = $reflectionFunc->getParameters();
var_dump($reflectionParams[0]->getType()->isBuiltin());
var_dump($reflectionParams[1]->getType()->isBuiltin());
var_dump($reflectionParams[2]->getType()->isBuiltin());
The above example will output:
bool(true) bool(false) bool(false)
Note that the ReflectionNamedType::isBuiltin() method does not distinguish between internal and custom classes. To make this distinction, the ReflectionClass::isInternal() method should be used on the returned class name.
I couldn't find a list of what qualifies as a builtin. Here is what I have so far:
string
float
bool
int
iterable (Iterator reflects as type iterable)
mixed
array
These do not qualify as builtins:
Closure
Stringable
Generator
Traversable
Serializable
Throwable
IteratorAggregate
ArrayAccess
WeakReference
JsonSerializeable
built-in types () are:
- `array`
- `callable`
- `bool`
- `float`
- `int`
- `string`
- `iterable`
- `object`
- `mixed`
Note: tested from the list at https://php.net/language.types.declarations#language.types.declarations.base
`self` & `parent` are not included.