ReflectionNamedType::isBuiltin
(PHP 7, PHP 8)
ReflectionNamedType::isBuiltin — 检查它是否是内置类型
说明
public ReflectionNamedType::isBuiltin(): bool
检查该类型是否是 PHP 中的内置类型。 内置类型是任何不是类、接口或 trait 的类型。
参数
此函数没有参数。
返回值
如果是内置类型返回 true
,否则为 false
。
范例
示例 #1 ReflectionNamedType::isBuiltin() 示例
<?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());
以上例程会输出:
bool(true) bool(false) bool(false)
注意:ReflectionNamedType::isBuiltin() 方法不区分内部类和 自定义类。为了区分,应该在返回的类名上使用 ReflectionClass::isInternal() 方法。
参见
- ReflectionType::allowsNull() - Checks if null is allowed
- ReflectionType::__toString() - To string
- ReflectionClass::isInternal() - 检查类是否由扩展或核心在内部定义
- ReflectionParameter::getType() - Gets a parameter's type

User Contributed Notes 2 notes
mndevel at gmail dot com ¶
1 year ago
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
yarns_purport0n at icloud dot com ¶
2 months ago
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.
备份地址:http://www.lvesu.com/blog/php/reflectionnamedtype.isbuiltin.php