コード例 #1
0
 /**
  * Return where a closure has been defined
  *
  * If for some reason this doesn't work - it'll return the closure instance in the full knowledge
  * that it'll probably get dumped as the string "function"
  *
  * @param Closure $closure
  * @return mixed string or Closure
  */
 protected function _getClosureDefinition(Closure $closure)
 {
     $exported = ReflectionFunction::export($closure, true);
     preg_match('#@@ (.*) (\\d+) - (\\d+)#', $exported, $match);
     if (!$match) {
         return $closure;
     }
     list($m, $path, $start) = $match;
     $path = Debugger::trimPath($path);
     return "{$path}:{$start}";
 }
コード例 #2
0
ファイル: reflection.php プロジェクト: alphaxxl/hhvm
var_dump($rf->getStaticVariables());
print "\n";
/**
 * This is g's doc comment.
 */
function g($a = null, $b = array(1, 2, 3), $c = SOME_CONSTANT)
{
    print "In g({$a}, {$b}, {$c})\n";
}
$rg = new ReflectionFunction("g");
print "--- invoke(\"g\") ---\n";
var_dump($rg->invoke("a", "b"));
var_dump($rg->invoke("a", "b"));
print "\n";
print "--- export(\"g\") ---\n";
var_dump($rf->export('g', true));
print "\n";
#===============================================================================
# ReflectionClass.
interface H
{
    public function methH();
}
interface I
{
    public function methI();
}
interface J
{
    public function methJ();
}
 /**
  * Tests export.
  */
 public function testToString()
 {
     $tests = array('lines', 'docComment', 'noComment', 'invoke', 'noParameters', 'parameters', 'reference', 'noReference', 'noNamespace', 'userDefined', 'noClosure');
     foreach ($tests as $test) {
         $rfl = $this->getFunctionReflection($test);
         $this->assertSame($rfl->internal->__toString(), $rfl->token->__toString());
         $this->assertSame(InternalReflectionFunction::export($this->getFunctionName($test), true), ReflectionFunction::export($this->getBroker(), $this->getFunctionName($test), true));
         // Test loading from a string
         $rfl = $this->getFunctionReflection($test, true);
         $this->assertSame($rfl->internal->__toString(), $rfl->token->__toString());
     }
     $this->assertSame(InternalReflectionFunction::export('strpos', true), ReflectionFunction::export($this->getBroker(), 'strpos', true));
 }
コード例 #4
0
ファイル: test_math.php プロジェクト: AaronAsAChimp/gfonted
$func = new ReflectionFunction('clamp');

for($i = $min - .5; $i < $max + .5; $i += 0.01) {
	echo "<tr><td>";
	echo $i,"</td><td>";
	var_dump($func->invokeArgs(Array($i, $max, $min)));
	echo "</td></tr>";
}
?>
</table>

<h1>Test random_val</h1>
<pre>
<?php 
echo ReflectionFunction::export('random_val');
?>
</pre>

<table>
<?
$max = -0.06;
$min = 0.06;
$func = new ReflectionFunction('random_val');

for($i = 0; $i < 50; $i++) {
	echo "<tr><td>";
	echo $i,"</td><td>";
	var_dump($func->invokeArgs(Array($max, $min)));
	echo "</td></tr>";
}
コード例 #5
0
 public function testExport()
 {
     self::assertEquals(ReflectionFunction::export('m1', true), ezcReflectionFunction::export('m1', true));
     self::assertEquals(ReflectionFunction::export('m2', true), ezcReflectionFunction::export('m2', true));
     self::assertEquals(ReflectionFunction::export('m3', true), ezcReflectionFunction::export('m3', true));
 }
コード例 #6
0
 /**
  * Exports a ReflectionFunction object.
  *
  * Returns the output if TRUE is specified for $return, printing it otherwise.
  * This is purely a wrapper method, which calls the corresponding method of
  * the parent class (ReflectionFunction::export()).
  * @param string $function Name of the function
  * @param boolean $return
  *        Whether to return (TRUE) or print (FALSE) the output
  * @return mixed
  */
 public static function export($function, $return = false)
 {
     return parent::export($function, $return);
 }
コード例 #7
0
ファイル: test_date.php プロジェクト: AaronAsAChimp/gfonted
<h1>Test Format Duration</h1>
<pre>
<?php 
require_once "utility/date.php";
echo ReflectionFunction::export('format_duration');
?>
</pre>

<table>
<?
$max = 3601;
$min = 1;

$func = new ReflectionFunction('format_duration');

for($i = $min; $i < $max; $i++) {
	echo "<tr><td>";
	echo $i,"</td><td>";
	var_dump($func->invokeArgs(Array($i)));
	echo "</td></tr>";
}
?>
</table>

コード例 #8
0
<pre><?php 
/**
 * @see http://php.net/manual/en/class.reflection.php
 * @version PHP 5+
 */
function myFunction($param1 = 'World')
{
    return "Hello {$param1}!";
}
var_dump(get_defined_functions()['user']);
var_dump(ReflectionFunction::export('myFunction', true));
echo '<hr />';
class Person
{
    public $name;
    protected $spouse;
    private $password;
    /**
     * My constructor
     * @param string $name
     */
    public function __construct($name)
    {
        $this->name = $name;
    }
    public function getName()
    {
        return $this->name;
    }
    public function setSpouse(Person $spouse)
    {
コード例 #9
0
ファイル: 025.php プロジェクト: badlamer/hhvm
<?php

/**
hoho
*/
function test($a, $b = 1, $c = "")
{
    static $var = 1;
}
$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)));