Esempio n. 1
0
function main()
{
    $c = new C();
    B::test($c);
    C::test($c);
    D::test($c);
}
Esempio n. 2
0
function main()
{
    $a = new A();
    $b = new B();
    $c = new C();
    B::test($a);
    C::test($b);
    E::test($c);
}
Esempio n. 3
0
 public static function testNoForward()
 {
     A::test();
     call_user_func("A::test");
     call_user_func(array("A", "test"));
     B::test();
     call_user_func("B::test");
     call_user_func(array("B", "test"));
 }
Esempio n. 4
0
function main()
{
    call_user_func(array('A', 'private_func'), "1", "2", "3");
    call_user_func(array('A', 'protected_func'), "1", "2", "3");
    call_user_func(array('A', 'public_func'), "1", "2", "3");
    call_user_func(array('B', 'private_func'), "1", "2", "3");
    call_user_func(array('B', 'protected_func'), "1", "2", "3");
    call_user_func(array('B', 'public_func'), "1", "2", "3");
    A::test();
    B::test();
}
Esempio n. 5
0
 public static function mycatch()
 {
     try {
         static::who();
         B::throwException_after();
     } catch (Exception $e) {
         static::who();
         A::test();
         static::who();
         B::test();
         static::who();
         self::simpleCatch();
         static::who();
     }
 }
Esempio n. 6
0
<?php

class A
{
    protected $fld = 42;
    public function test()
    {
        var_dump($this->fld);
    }
}
class B extends A
{
    protected $fld = 2;
}
$a = new A();
$b = new B();
$a->test();
$b->test();
Esempio n. 7
0
<?php

class A
{
    protected $a;
    public function __construction()
    {
        echo __CLASS__;
    }
    public function test()
    {
        $b = new self();
        var_dump($this->a);
        die;
        return $b->a;
    }
    public function setA($a)
    {
        $this->a = $a;
    }
}
class B extends A
{
    public function test1()
    {
    }
}
$a = new B();
$a->setA(1);
$b = $a->test();
var_dump($b);
Esempio n. 8
0
 static function test()
 {
     $b = new B();
     $b->text = [];
     $b->test([1, 2, 3]);
 }
<?php

trait TestTrait
{
    public static function test()
    {
        return 'Forwarded ' . forward_static_call(array('A', 'test'));
    }
}
class A
{
    public static function test()
    {
        return "Test A";
    }
}
class B extends A
{
    use TestTrait;
}
echo B::test();
Esempio n. 10
0
<?php

class A
{
    private static function testprivate()
    {
        return 1;
    }
    public static function test()
    {
        return function () {
            return self::testprivate();
        };
    }
}
class B extends A
{
}
$fn = B::test();
echo $fn();
Esempio n. 11
0
    public function __sleep()
    {
        return $GLOBALS['g'];
    }
    static function test($a, $elems, $p = null)
    {
        global $g;
        $a->seta(42);
        $g = $elems;
        $s = serialize($a);
        var_export($s);
        echo "\n";
        $u = unserialize($s);
        var_dump($u);
        if ($p) {
            var_dump($u->{$p});
        }
    }
}
B::test(new A(), array("a"));
B::test(new A(), array("Aa"));
B::test(new A(), array("*a"));
B::test(new A(), array("*b"), "b");
B::test(new A(), array("Bb"), "b");
B::test(new A(), "foo");
B::test(new B(), array("a"));
B::test(new B(), array("Aa"));
B::test(new B(), array("*a"));
B::test(new B(), array("*b"), "b");
B::test(new B(), array("Bb"), "b");
Esempio n. 12
0
<?php

class A
{
    const NAME = 'A';
    public static function test()
    {
        $args = func_get_args();
        echo static::NAME, " " . join(',', $args) . " \n";
    }
}
class B extends A
{
    const NAME = 'B';
    public static function test()
    {
        echo self::NAME, "\n";
        forward_static_call(array('A', 'test'), 'more', 'args');
        forward_static_call('test', 'other', 'args');
    }
}
B::test('foo');
function test()
{
    $args = func_get_args();
    echo "C " . join(',', $args) . " \n";
}
Esempio n. 13
0
<?php

class A
{
    public static function test($x = null)
    {
        if (!is_null($x)) {
            echo "{$x}\n";
        }
        return get_called_class();
    }
}
class B extends A
{
}
class C extends A
{
}
class D extends A
{
}
echo A::test(B::test(C::test(D::test()))) . "\n";
?>
==DONE==
Esempio n. 14
0
        var_dump(get_object_vars($b));
    }
}
class C extends B
{
    private $hiddenPriv = 'C::hiddenPriv';
    public static function test($b)
    {
        echo __METHOD__ . "\n";
        var_dump(get_object_vars($b));
    }
}
class X
{
    public static function test($b)
    {
        echo __METHOD__ . "\n";
        var_dump(get_object_vars($b));
    }
}
$b = new B();
echo "\n---( Global scope: )---\n";
var_dump(get_object_vars($b));
echo "\n---( Declaring class: )---\n";
B::test($b);
echo "\n---( Subclass: )---\n";
C::test($b);
echo "\n---( Superclass: )---\n";
A::test($b);
echo "\n---( Unrelated class: )---\n";
X::test($b);
}
EventLoop::$instance = new EventLoop();
class A
{
    protected $ev;
    public function __construct(EventLoop $ev)
    {
        $this->ev = $ev;
    }
    public function test()
    {
        return $this->ev;
    }
}
class B
{
    public function test()
    {
        return EventLoop::$instance;
    }
}
$aInstance = new A(new EventLoop());
$benchmark->add('without-static-normal-injection', function () use($aInstance) {
    return $aInstance->test();
});
$bInstance = new B();
$benchmark->add('with-static-global-state', function () use($bInstance) {
    return $bInstance->test();
});
$benchmark->setCount(10000000);
$benchmark->run();
Esempio n. 16
0
<?php

interface I
{
    public function test($a);
}
class A
{
    public function test($a)
    {
        print 'A';
    }
}
class B extends A implements I
{
    public function test($a)
    {
        print 'B';
    }
}
$obj = new A();
$obj->test(1);
$obj = new B();
$obj->test(1);
Esempio n. 17
0
<?php

class A
{
    public $a = 1;
}
class B extends A
{
    public $m = 10;
    public function test()
    {
        $b = 'a';
        $this->{$b} = 'test';
        var_dump($this->{$b});
        var_dump($this->a);
        $c =& $this->{$b};
        $c = array(1);
        var_dump($this->a);
    }
}
$obj = new B();
$obj->test();
Esempio n. 18
0
<?php

//src: http://php.net/manual/en/language.oop5.late-static-bindings.php
class A
{
    public static function who()
    {
        echo __CLASS__;
    }
    public static function test()
    {
        static::who();
        // Here comes Late Static Bindings
    }
}
class B extends A
{
    public static function who()
    {
        echo __CLASS__;
    }
}
// should print "B"
B::test();
Esempio n. 19
0
<?php

class A
{
    public $a;
    protected $b;
    private $c;
    public function __construct()
    {
        $this->a = 1;
        $this->b = 2;
        $this->c = 3;
    }
    public function test()
    {
        //exit('ss');
    }
}
class B extends A
{
    public function test()
    {
        echo $this->a;
    }
}
$aa = new B();
$aa->test();
//echo $aa->a = 10;
//echo $aa->b = 101;
//echo $aa->c = 101;