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


PHP ReflectionFunction::returnsReference方法代码示例

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


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

 static function castClosure($c)
 {
     $a = array();
     if (!class_exists('ReflectionFunction', false)) {
         return $a;
     }
     $c = new \ReflectionFunction($c);
     foreach ($c->getParameters() as $p) {
         $n = ($p->isPassedByReference() ? '&$' : '$') . $p->getName();
         if ($p->isDefaultValueAvailable()) {
             $a[$n] = $p->getDefaultValue();
         } else {
             $a[] = $n;
         }
     }
     $m = self::META_PREFIX;
     $a = array($m . 'returnsRef' => true, $m . 'args' => $a);
     if (!$c->returnsReference()) {
         unset($a[$m . 'returnsRef']);
     }
     $a[$m . 'use'] = array();
     if (false === ($a[$m . 'file'] = $c->getFileName())) {
         unset($a[$m . 'file']);
     } else {
         $a[$m . 'lines'] = $c->getStartLine() . '-' . $c->getEndLine();
     }
     if (!($c = $c->getStaticVariables())) {
         unset($a[$m . 'use']);
     } else {
         foreach ($c as $p => &$c) {
             $a[$m . 'use']['$' . $p] =& $c;
         }
     }
     return $a;
 }
开发者ID:nicolas-grekas,项目名称:Patchwork-sandbox,代码行数:35,代码来源:Caster.php

示例3: function_signature

function function_signature($function_name)
{
    try {
        $rf = new ReflectionFunction($function_name);
    } catch (Exception $e) {
        return null;
    }
    $params = array();
    $unknown_param_name = 'unk0';
    foreach ($rf->getParameters() as $rp) {
        $param = $rp->isPassedByReference() ? '&' : '';
        $name = $rp->getName();
        if ($name == '') {
            $name = '$' . $unknown_param_name;
            $unknown_param_name++;
        } elseif ($name == '...') {
        } else {
            $name = '$' . $name;
        }
        $param .= $name;
        if ($rp->isOptional()) {
            $param .= ' = null';
            // is there better way to show that it's optional?
        }
        $params[] = $param;
    }
    $str = "";
    $str .= $rf->returnsReference() ? '&' : '';
    $str .= $rf->getName();
    $str .= '(' . implode(", ", $params) . ')';
    return $str;
}
开发者ID:gariev,项目名称:xref,代码行数:32,代码来源:funcitons.php

示例4: testMatchReflector

 public function testMatchReflector()
 {
     $function = FunctionDeclarationNode::create('array_walk');
     $reflector = new \ReflectionFunction('array_walk');
     // $function->getReference() should return a TokenNode or NULL, which will
     // loosely evaluate to TRUE or FALSE
     $this->assertEquals($function->getReference(), $reflector->returnsReference());
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:8,代码来源:FunctionDeclarationNodeTest.php

示例5: returnsReference

 /**
  * Returns whether this function returns a reference
  *
  * @return boolean True if this function returns a reference
  */
 public function returnsReference()
 {
     if ($this->reflectionSource instanceof ReflectionFunction) {
         return $this->reflectionSource->returnsReference();
     } else {
         return parent::returnsReference();
     }
 }
开发者ID:zetacomponents,项目名称:reflection,代码行数:13,代码来源:function.php

示例6: fromReflection

 public static function fromReflection(\ReflectionFunction $ref)
 {
     $function = PhpFunction::create($ref->name)->setReferenceReturned($ref->returnsReference())->setBody(ReflectionUtils::getFunctionBody($ref));
     $docblock = new Docblock($ref);
     $function->setDocblock($docblock);
     $function->setDescription($docblock->getShortDescription());
     $function->setLongDescription($docblock->getLongDescription());
     foreach ($ref->getParameters() as $refParam) {
         assert($refParam instanceof \ReflectionParameter);
         // hmm - assert here?
         $param = PhpParameter::fromReflection($refParam);
         $function->addParameter($param);
     }
     return $function;
 }
开发者ID:jmcclell,项目名称:php-code-generator,代码行数:15,代码来源:PhpFunction.php

示例7: fromReflection

 public static function fromReflection(\ReflectionFunction $ref)
 {
     $function = new static();
     if (false === ($pos = strrpos($ref->name, '\\'))) {
         $function->setName(substr($ref->name, $pos + 1));
         $function->setNamespace(substr($ref->name, $pos));
     } else {
         $function->setName($ref->name);
     }
     $function->referenceReturned = $ref->returnsReference();
     $function->docblock = ReflectionUtils::getUnindentedDocComment($ref->getDocComment());
     foreach ($ref->getParameters() as $refParam) {
         assert($refParam instanceof \ReflectionParameter);
         $param = PhpParameter::fromReflection($refParam);
         $function->addParameter($param);
     }
     return $function;
 }
开发者ID:ingeniorweb,项目名称:symfo3cv,代码行数:18,代码来源:PhpFunction.php

示例8: getFunctionSignature

 /**
  * Returns the signature of a function.
  *
  * @param  ReflectionFunction $function
  * @return string
  * @since  Method available since Release 3.3.2
  * @todo   Find a better place for this method.
  */
 public static function getFunctionSignature(ReflectionFunction $function)
 {
     if ($function->returnsReference()) {
         $reference = '&';
     } else {
         $reference = '';
     }
     return sprintf('function %s%s(%s)', $reference, $function->getName(), self::getMethodParameters($function));
 }
开发者ID:amptools-net,项目名称:midori-php,代码行数:17,代码来源:Class.php

示例9: getParameters

var_dump($rf->getNumberOfRequiredParameters());
print "\n";
print "--- getParameters(\"f\") ---\n";
var_dump($rf->getParameters());
print "\n";
print "--- getStaticVariables(\"f\") ---\n";
var_dump($rf->getStaticVariables());
print "\n";
print "--- isInternal(\"f\") ---\n";
var_dump($rf->isInternal());
print "\n";
print "--- isUserDefined(\"f\") ---\n";
var_dump($rf->isUserDefined());
print "\n";
print "--- returnsReference(\"f\") ---\n";
var_dump($rf->returnsReference());
print "\n";
print "--- export(\"f\") ---\n";
var_dump($rf->export('f', true));
print "\n";
# invoke() can't be used because $b is pass-by-reference.
print "--- invokeArgs(\"f\") ---\n";
$b = "b";
var_dump($rf->invokeArgs(array("a", &$b, "c")));
var_dump($rf->invokeArgs(array("a", &$b, "c")));
print "\n";
print "--- getStaticVariables(\"f\") ---\n";
$rf = new ReflectionFunction("f");
var_dump($rf->getStaticVariables());
print "\n";
/**
开发者ID:alphaxxl,项目名称:hhvm,代码行数:31,代码来源:reflection.php

示例10: getFunctionByReflection

 /**
  * @param ReflectionMethod $rm
  * @return XRef_Function
  */
 private function getFunctionByReflection(ReflectionFunction $rf)
 {
     $m = new XRef_Function();
     $m->name = $rf->getName();
     $m->index = $m->bodyStarts = $m->bodyEnds = $m->nameIndex = -1;
     $m->isDeclaration = false;
     $m->returnsReference = $rf->returnsReference();
     foreach ($rf->getParameters() as $rp) {
         $p = new XRef_FunctionParameter();
         $p->hasDefaultValue = $rp->isOptional();
         $p->name = $rp->getName();
         $p->isPassedByReference = $rp->isPassedByReference();
         $m->parameters[] = $p;
     }
     return $m;
 }
开发者ID:gariev,项目名称:xref,代码行数:20,代码来源:ProjectDatabase.class.php

示例11: array

<?php

$funcs = get_defined_functions();
$output = "<?php\nuse PHPPHP\\Engine\\ParamData;\n\nreturn array(\n";
foreach ($funcs['internal'] as $func) {
    $output .= "    array('{$func}', ";
    $r = new ReflectionFunction($func);
    $output .= $r->returnsReference() ? 'true' : 'false';
    $output .= ', array(';
    foreach ($r->getParameters() as $param) {
        $output .= "new ParamData('" . $param->getName() . "', ";
        $output .= $param->isPassedByReference() ? "true" : "false";
        if ($param->isArray()) {
            $output .= ", 'array', ";
        } else {
            $output .= ", '', ";
        }
        $output .= $param->isOptional() ? "true" : 'false';
        $output .= "), ";
    }
    $output .= ")),\n";
}
$output .= ");";
file_put_contents(__DIR__ . '/aliases.php', $output);
开发者ID:asgrim,项目名称:PHPPHP,代码行数:24,代码来源:aliasBuilder.php

示例12: ReflectionFunction

$func = new ReflectionFunction("test");
var_dump($func->export("test"));
echo "--getName--\n";
var_dump($func->getName());
echo "--isInternal--\n";
var_dump($func->isInternal());
echo "--isUserDefined--\n";
var_dump($func->isUserDefined());
echo "--getFilename--\n";
var_dump($func->getFilename());
echo "--getStartline--\n";
var_dump($func->getStartline());
echo "--getEndline--\n";
var_dump($func->getEndline());
echo "--getDocComment--\n";
var_dump($func->getDocComment());
echo "--getStaticVariables--\n";
var_dump($func->getStaticVariables());
echo "--invoke--\n";
var_dump($func->invoke(array(1, 2, 3)));
echo "--invokeArgs--\n";
var_dump($func->invokeArgs(array(1, 2, 3)));
echo "--returnsReference--\n";
var_dump($func->returnsReference());
echo "--getParameters--\n";
var_dump($func->getParameters());
echo "--getNumberOfParameters--\n";
var_dump($func->getNumberOfParameters());
echo "--getNumberOfRequiredParameters--\n";
var_dump($func->getNumberOfRequiredParameters());
echo "Done\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:025.php


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