PHP 8.3.0 RC 6 available for testing

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() 方法。

参见

add a note

User Contributed Notes 2 notes

up
7
mndevel at gmail dot com
2 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
up
2
yarns_purport0n at icloud dot com
1 year 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.
To Top