示例#1
0
 public function testSpy()
 {
     $dependency = $this->prophesize(\Foo\DependencyInterface::class);
     $foo = new Foo($dependency->reveal());
     $foo->baz();
     $dependency->boolGenerator(1)->shouldHaveBeenCalled();
 }
示例#2
0
文件: 2085.php 项目: badlamer/hhvm
<?php

trait Too
{
    function bar()
    {
        $abc = 123;
        $a = function ($x) use($abc) {
            $n = func_num_args();
            $args = func_get_args();
            var_dump($n, $args);
        };
        return $a;
    }
    function baz($obj)
    {
        $abc = 456;
        $obj(789);
    }
}
class Foo
{
    use Too;
}
$a = Foo::bar();
Foo::baz($a);
示例#3
0
<?php

class Foo
{
    public function baz()
    {
    }
}
/**
 * get_foo
 *
 * @access public
 * @return Foo
 */
function get_foo()
{
}
get_foo()->baz();
Foo::baz();
$f2 = new \NS2\Foo2();
$f2->returnBaz2()->returnFoo2();
?>


示例#4
0
<?php

class Bar
{
}
class Foo
{
    public function baz($x)
    {
        if ($x instanceof Foo && true) {
            echo "wheeee\n";
        }
        if ($x instanceof Bar) {
            echo "TGIF\n";
        }
    }
}
$f = new Foo();
$f->baz($f);
示例#5
0
<?php

require_once $GLOBALS["HACKLIB_ROOT"];
class Foo
{
    public function bar()
    {
        (yield 5);
        return;
    }
    public static function baz()
    {
        if (false) {
            (yield false);
        }
        return;
    }
}
foreach (Foo::baz() as $v) {
    echo $v . "\n";
}
echo "break\n";
$f = new Foo();
foreach ($f->bar() as $v) {
    echo $v . "\n";
}
示例#6
0
文件: get_class.php 项目: hnw/php425
<?php

class Foo
{
    function Baz()
    {
        echo get_class($this) . "\n";
        echo get_parent_class($this) . "\n";
    }
}
class Bar extends Foo
{
}
$foo = new Foo();
$foo->baz();
$bar = new Bar();
$bar->baz();
示例#7
0
    // some regular method
    public function baz($message)
    {
        echo $message . PHP_EOL;
    }
    // you need to set this up if you want to call
    // a closure object data member as a regular method
    // Why this is the case is unclear
    public function __call($method, $args)
    {
        echo "I am here ...\n";
        $closure = $this->{$method};
        call_user_func_array($closure, $args);
    }
}
$foo = new Foo();
// some closure object
$func = function ($baz) {
    echo strtoupper($baz) . PHP_EOL;
};
// closure object assigned to data member
$foo->bar = $func;
// cannot call data member (despite being closure object)
// unless __call class method as been set up ...
$foo->bar('lorem ipsum dolor sit amet');
// regular method calls unaffected by __call method
$foo->baz('this is a normal method call');
// additional comments
$myArray = ["This is a message"];
// this feels a little bit like the Scheme 'apply' function
call_user_func_array($func, $myArray);
示例#8
0
 public static function bar()
 {
     self::$baz = 1;
 }