ReflectionNamedType::isBuiltin
(PHP 7, PHP 8)
ReflectionNamedType::isBuiltin — 检查它是否是内置类型
参数
此函数没有参数。
示例
示例 #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
+添加备注
用户贡献的备注 2 notes
mndevel at gmail dot com ¶
3 years 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 years 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