Exemplo n.º 1
0
 public function baz(Test $other)
 {
     echo $other->foo . "\n";
     // We can change the private property:
     $other->foo = 'hello';
     var_dump($other->foo);
     // We can also call the private method:
     $other->bar();
 }
Exemplo n.º 2
0
 public function baz(Test $other)
 {
     // Мы можем изменить закрытое свойство:
     $other->foo = 'hello';
     var_dump($other->foo);
     // Мы также можем вызвать закрытый метод:
     $other->bar();
 }
Exemplo n.º 3
0
 public function test()
 {
     $foo = new Test();
     $this->assertTrue($foo->bar());
     $this->assertFalse($foo->baz());
 }
Exemplo n.º 4
0
    public function __call($method, $args)
    {
    }
}
function do_throw()
{
    throw new Exception();
}
try {
    Test::foo(do_throw());
} catch (Exception $e) {
    echo "Caught!\n";
}
try {
    (new Test())->bar(do_throw());
} catch (Exception $e) {
    echo "Caught!\n";
}
try {
    $f = function () {
    };
    $f->__invoke(do_throw());
} catch (Exception $e) {
    echo "Caught!\n";
}
try {
    $t = new Test();
    $f->__invoke($t->bar(Test::foo(do_throw())));
} catch (Exception $e) {
    echo "Caught!\n";
}
Exemplo n.º 5
0
<?php

interface TestInterface
{
    public function foo();
    public function bar(array $bar);
}
class Test implements TestInterface
{
    public function foo(...$args)
    {
        echo __METHOD__, "\n";
    }
    public function bar(array $bar, ...$args)
    {
        echo __METHOD__, "\n";
    }
}
$obj = new Test();
$obj->foo();
$obj->bar([]);