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

    版本:php7

    (PHP 7)

    Checks if parameter has a type

    说明

    publicReflectionParameter::hasType(void) : bool

    Checks if the parameter has a type associated with it.

    参数

    此函数没有参数。

    返回值

    TRUEif a type is specified,FALSEotherwise.

    范例

    Example #1ReflectionParameter::hasType()example

    <?php
    function someFunction(string $param, $param2 = null) {}
    $reflectionFunc = new ReflectionFunction('someFunction');
    $reflectionParams = $reflectionFunc->getParameters();
    var_dump($reflectionParams[0]->hasType());
    var_dump($reflectionParams[1]->hasType());

    以上例程的输出类似于:

    bool(true)
    bool(false)
    

    参见

    • ReflectionParameter::getType() Gets a parameter's type