当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionFunction::getReturnType方法代码示例

本文整理汇总了PHP中ReflectionFunction::getReturnType方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunction::getReturnType方法的具体用法?PHP ReflectionFunction::getReturnType怎么用?PHP ReflectionFunction::getReturnType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionFunction的用法示例。


在下文中一共展示了ReflectionFunction::getReturnType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: from

 /**
  * @return self
  */
 public static function from($from) : self
 {
     if (is_string($from) && strpos($from, '::')) {
         $from = new \ReflectionMethod($from);
     } elseif (is_array($from)) {
         $from = new \ReflectionMethod($from[0], $from[1]);
     } elseif (!$from instanceof \ReflectionFunctionAbstract) {
         $from = new \ReflectionFunction($from);
     }
     $method = new static();
     $method->name = $from->isClosure() ? NULL : $from->getName();
     foreach ($from->getParameters() as $param) {
         $method->parameters[$param->getName()] = Parameter::from($param);
     }
     if ($from instanceof \ReflectionMethod) {
         $method->static = $from->isStatic();
         $method->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : NULL);
         $method->final = $from->isFinal();
         $method->abstract = $from->isAbstract() && !$from->getDeclaringClass()->isInterface();
         $method->body = $from->isAbstract() ? FALSE : '';
     }
     $method->returnReference = $from->returnsReference();
     $method->variadic = PHP_VERSION_ID >= 50600 && $from->isVariadic();
     $method->comment = $from->getDocComment() ? preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t")) : NULL;
     if (PHP_VERSION_ID >= 70000 && $from->hasReturnType()) {
         $returnType = $from->getReturnType();
         $method->returnType = $returnType->isBuiltin() ? (string) $returnType : '\\' . $returnType;
     }
     return $method;
 }
开发者ID:kukulich,项目名称:php-generator,代码行数:33,代码来源:Method.php

示例2: getReturnType

 public function getReturnType() : Type
 {
     if ($this->returnType === null) {
         $phpTypeReflection = $this->reflection->getReturnType();
         if ($phpTypeReflection === null) {
             $this->returnType = new MixedType(true);
         } else {
             $this->returnType = TypehintHelper::getTypeObjectFromTypehint((string) $phpTypeReflection, $phpTypeReflection->allowsNull());
         }
     }
     return $this->returnType;
 }
开发者ID:phpstan,项目名称:phpstan,代码行数:12,代码来源:FunctionReflection.php

示例3: getRealClassName

 public static function getRealClassName($value)
 {
     if (!is_callable($value)) {
         return null;
     }
     $closure = new \ReflectionFunction($value);
     if ($closure->hasReturnType() !== false) {
         $returnedType = $closure->getReturnType();
         if ($returnedType->isBuiltin() === false && class_exists((string) $returnedType)) {
             return (string) $returnedType;
         }
     }
     return null;
 }
开发者ID:erickjth,项目名称:SimpleServicesInjector,代码行数:14,代码来源:AliasBuilder.php

示例4: validateSignature

 private function validateSignature(callable $filter = null)
 {
     $reflection = new \ReflectionFunction($filter);
     if ($reflection->getNumberOfParameters() !== 1) {
         throw new \Exception("invalid number of parameters");
     }
     $parameter = $reflection->getParameters()[0];
     $name = $parameter->getName();
     if (!$parameter->hasType()) {
         throw new \Exception("missing required type for parameter '{$name}'");
     }
     $type = $parameter->getType();
     if ((string) $type !== "ReflectionClass") {
         throw new \Exception("invalid type for type for parameter '{$name}'");
     }
     if (!$reflection->hasReturnType()) {
         throw new \Exception("missing required return type");
     }
     $returnType = $reflection->getReturnType();
     if ((string) $returnType !== "bool") {
         throw new \Exception("invalid return type");
     }
 }
开发者ID:sndsgd,项目名称:fs,代码行数:23,代码来源:ClassLocatorFilterValidator.php

示例5: foo

<?php

function foo(int $a) : bool
{
}
$rf = new ReflectionFunction('foo');
echo "--Parameter--\n\n";
$rp = $rf->getParameters()[0];
var_dump($rp->hasType());
$rt = $rp->getType();
var_dump($rt->isBuiltin());
var_dump($rt->__toString());
var_dump($rt->allowsNull());
echo "\n--Return--\n\n";
var_dump($rf->hasReturnType());
$rt = $rf->getReturnType();
var_dump($rt->isBuiltin());
var_dump($rt->__toString());
var_dump($rt->allowsNull());
echo "\n--Call Constructor Directly--\n\n";
// There is a public constructor; we differ with PHP 7 a bit here. In PHP 7
// you can call the public constructor from user code and then you fatal on
// the first method call to the instance. In HHVM, you can call the constructor
// directly, but you have to have an instance of ReflectionParameter or
// ReflectionFunctionAbstract.
$rt2 = new ReflectionType($rp);
// this returns false since we didn't pass any info to the constructor
var_dump($rt2->isBuiltin());
// This will trigger an error since it is not ReflectionParameter or
// ReflectionFunctionAbstract
$rt3 = new ReflectionType(new ReflectionClass('Exception'));
开发者ID:RavuAlHemio,项目名称:hhvm,代码行数:31,代码来源:ReflectionType-basic-explicit-php7.php

示例6: testGetReturnTypeMethod

 public function testGetReturnTypeMethod()
 {
     if (PHP_VERSION_ID < 70000) {
         $this->markTestSkipped('Test available only for PHP7.0 and newer');
     }
     $fileName = stream_resolve_include_path(__DIR__ . self::STUB_FILE70);
     $reflectionFile = new ReflectionFile($fileName);
     include $fileName;
     foreach ($reflectionFile->getFileNamespaces() as $fileNamespace) {
         foreach ($fileNamespace->getFunctions() as $refFunction) {
             $functionName = $refFunction->getName();
             $originalRefFunction = new \ReflectionFunction($functionName);
             $hasReturnType = $refFunction->hasReturnType();
             $this->assertSame($originalRefFunction->hasReturnType(), $hasReturnType, "Presence of return type for function {$functionName} should be equal");
             if ($hasReturnType) {
                 $parsedReturnType = $refFunction->getReturnType();
                 $originalReturnType = $originalRefFunction->getReturnType();
                 $this->assertSame($originalReturnType->allowsNull(), $parsedReturnType->allowsNull());
                 $this->assertSame($originalReturnType->isBuiltin(), $parsedReturnType->isBuiltin());
                 $this->assertSame($originalReturnType->__toString(), $parsedReturnType->__toString());
             } else {
                 $this->assertSame($originalRefFunction->getReturnType(), $refFunction->getReturnType());
             }
         }
     }
 }
开发者ID:goaop,项目名称:parser-reflection,代码行数:26,代码来源:ReflectionFunctionTest.php

示例7: typeByReturnType

 private function typeByReturnType($class_name, $name)
 {
     try {
         if ($class_name) {
             $reflection = new \ReflectionClass($class_name);
             $reflection = $reflection->getMethod($name);
         } else {
             $reflection = new \ReflectionFunction($name);
         }
         $type = (string) $reflection->getReturnType();
         if (strtolower($type) == 'self') {
             $type = $class_name;
         }
         return $type;
     } catch (\ReflectionException $e) {
         $this->logger->debug((string) $e);
     }
 }
开发者ID:przepompownia,项目名称:phpcd.vim,代码行数:18,代码来源:PHPCD.php

示例8: typeByReturnType

 private function typeByReturnType($class_name, $name)
 {
     try {
         if ($class_name) {
             $reflection = new ReflectionClass($class_name);
             $reflection = $reflection->getMethod($name);
         } else {
             $reflection = new ReflectionFunction($name);
         }
         $type = $reflection->getReturnType();
         return (string) $type;
     } catch (ReflectionException $e) {
         $this->log((string) $e);
     }
 }
开发者ID:ErrEoE,项目名称:phpcd.vim,代码行数:15,代码来源:PHPCD.php


注:本文中的ReflectionFunction::getReturnType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。