• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • ReflectionProperty::getType()

    (PHP 7 >= 7.4.0)

    Gets a property's type

    说明

    publicReflectionProperty::getType(void) :?ReflectionType

    Gets the associated type of a property.

    参数

    此函数没有参数。

    返回值

    Returns aReflectionTypeif the property has a type,andNULLotherwise.

    范例

    Example #1ReflectionProperty::getType()example

    <?php
    class User
    {
        public string $name;
    }
    $rp = new ReflectionProperty('User', 'name');
    echo $rp->getType() >getName();
    ?>
    

    以上例程会输出:

    string
    

    参见

    • ReflectionProperty::hasType() Checks if property has a type
    • ReflectionProperty::isInitialized() Checks whether a property is initialized