Пример #1
0
 public static function test()
 {
     // FPushClsMethodD
     C::foo("a", "b", "c", "d");
     // FPushClsMethod
     $cls = 'C';
     $cls::foo("a", "b", "c", "d");
     $fn = 'foo';
     C::$fn("a", "b", "c", "d");
     $fn = 'foo';
     $cls::$fn("a", "b", "c", "d");
     // FPushClsMethodF
     self::foo("a", "b", "c", "d");
 }
Пример #2
0
function main()
{
    $c = new C();
    $d = new D();
    $c->foo();
    $d->foo();
    echo "**************\n";
    $c->bar();
    $d->bar();
    echo "**************\n";
    C::foo();
    D::bar();
    echo "**************\n";
    $d->yar();
    D::yar();
}
Пример #3
0
<?php

class C
{
    function foo()
    {
        if ($this) {
            return true;
        } else {
            return false;
        }
    }
}
var_dump(C::foo());
Пример #4
0
 public static function callByParent()
 {
     parent::foo();
 }
Пример #5
0
<?php

// Copyright 2004-2015 Facebook. All Rights Reserved.
echo "Starting\n";
class C
{
    public function foo()
    {
        echo "foo\n";
        $x = array();
        if ($x) {
            print_r($x);
        } else {
            print_r($x);
        }
    }
}
$c = new C();
$val = $c->foo();
echo $val;
echo "\n";
echo "Done\n";
Пример #6
0
<?php

trait T
{
    function foo()
    {
        echo "Foo";
        $this->bar();
    }
    abstract function bar();
}
class C
{
    use T;
    function bar()
    {
        echo "BAR!\n";
    }
}
$x = new C();
$x->foo();
Пример #7
0
{
    function foo($x, $y = 0);
}
interface J
{
    function foo($x, $y);
}
interface K
{
    function foo($x, $y = 0, array $z);
}
interface L
{
    function foo($x, $y, array $z = null);
}
interface M
{
    function foo($x, $y = 0, array $z = array());
}
class C implements I, J, K, L, M
{
    public function foo($x, $y = 0, array $z = null, array $a = null)
    {
        echo "{$x} {$y} {$z}\n";
    }
}
$obj = new C();
$obj->foo(1);
$obj->foo(1, 2);
$obj->foo(1, 2, null);
$obj->foo(1, 2, array());
Пример #8
0
<?php

class A
{
    public $a = null;
}
class B extends A
{
    public function foo()
    {
        var_dump($this->a);
    }
}
class C extends B
{
    public $a = 'test';
}
$obj = new C();
$obj->foo();
Пример #9
0
<?php

// Method invocation on $this
class C
{
    function foo($x, $y)
    {
        echo "C::foo({$x}, {$y})\n";
        $this->bar($y, $x);
    }
    function bar($x, $y)
    {
        echo "C::bar({$x}, {$y})\n";
    }
}
$c = new C();
$c->foo(1, 2);
Пример #10
0
 public function doFoo()
 {
     $this->foo();
     // G G G
     B::foo();
     // B B    (Zend: B G G) (Rule 1)
     C::foo();
     // C C    (Zend: C G G) (Rule 1)
     D::foo();
     // D D    (Zend: D G G) (Rule 1)
     F::foo();
     // F G G
     G::foo();
     // G G G
     H::foo();
     // H H    (Zend: H G G) (Rule 1)
     parent::foo();
     // F G G
     self::foo();
     // G G G
     static::foo();
     // G G G
     echo "****************\n";
 }
Пример #11
0
  <?php 
abstract class A
{
    public abstract function foo(int $x);
}
interface I
{
    function foo(int $x);
}
abstract class B extends A implements I
{
}
class C extends B
{
    public function foo(array $x = null)
    {
    }
}
$c = new C();
$c->foo(null);
echo "OK\n";
Пример #12
0
 function bar()
 {
     C::foo();
 }
Пример #13
0
function main()
{
    return B::foo() + C::foo();
}
Пример #14
0
<?php

class C
{
    public $y = 5;
    function foo($x)
    {
        return $x + $this->y;
    }
}
$o = new C();
echo $o->foo(3) . "\n";
Пример #15
0
<?php

class C
{
    /**
     * @param string
     * @param array
     */
    public function __call($method, $args)
    {
    }
}
$c = new C();
$c->foo('asdf');
Пример #16
0
    }
    public function foo($x)
    {
        $bar = function ($y) use($x) {
            return $this->stuff($x, $y);
        };
        return $bar(33);
    }
    public function bar($x)
    {
        $zeta = new_model($x);
        return function ($y) use($zeta) {
            return $this->stuff($y, $zeta);
        };
    }
}
function lam($b)
{
    $fn = function ($a) use($b) {
        return $a + $b;
    };
    $gn = function ($a) use($b) {
        $c = $b * 20;
        return $a + $b;
    };
    return $fn(10) + $gn(10);
}
var_dump(lam(42));
$c = new C();
var_dump($c->foo(20));
Пример #17
0
function bar()
{
    $obj = new C();
    $obj->foo(123);
}
Пример #18
0
<?php

class C
{
    public function foo($x, $str)
    {
        $y = $str ?: "Water";
        return $y . ": " . ($x < 100 ? ($x < 30 ? "cold" : "warm") . " water" : ($x > 200 ? "OMG" : "steam"));
    }
}
$c = new C();
echo $c->foo(17, "") . "\n";
Пример #19
0
<?php

print "Test begin\n";
interface I
{
    public static function foo();
}
class C implements I
{
    public static function foo($x)
    {
        echo 'Hello ' . $x . "\n";
    }
}
C::foo("5");
print "Test end\n";
Пример #20
0
<?php

print "Test begin\n";
interface I
{
    public function foo($x, $y);
}
class C implements I
{
    public function foo($x)
    {
        echo 'Hello ' . $x . "\n";
    }
}
$o = new C();
$o->foo("5");
print "Test end\n";
Пример #21
0
<?php

trait T
{
    public abstract function foo($x);
}
interface I
{
    public function foo($x);
}
abstract class B implements I
{
    use T;
}
class C extends B
{
    public function foo($x)
    {
        echo "{$x} \n";
    }
}
$obj = new C();
$obj->foo(1);
Пример #22
0
function foo()
{
    $k = new C();
    $k->foo();
}
Пример #23
0
<?php

trait T
{
    public abstract function bar();
    public function foo()
    {
        $this->bar();
    }
}
class B
{
    public function bar()
    {
        echo "I'm bar\n";
    }
}
class C extends B
{
    use T;
}
$o = new C();
$o->foo();
Пример #24
0
<?php

trait T1
{
    abstract function foo();
}
trait T2
{
    abstract function foo();
}
abstract class B
{
    use T1, T2;
}
class C extends B
{
    function foo()
    {
        return "hello\n";
    }
}
$o = new C();
echo $o->foo();
Пример #25
0
<?php

abstract class A
{
    protected abstract function foo();
}
class B extends A
{
    protected function foo()
    {
        echo "B::foo\n";
    }
}
class C extends A
{
    function foo()
    {
        $b = new B();
        $b->foo();
    }
}
$c = new C();
$c->foo();
Пример #26
0
<?php

class C
{
    var $x;
    function __construct($x)
    {
        $this->x = $x;
    }
    function foo($that)
    {
        var_dump($this->x);
        $this = $that;
        var_dump($this->x);
    }
}
$c1 = new C(1);
$c2 = new C(2);
$c1->foo($c2);
<?php

abstract class C
{
    static abstract function foo();
}
function foo(callable $x)
{
}
try {
    C::foo();
} catch (Error $e) {
    echo "\nException: " . $e->getMessage() . " in ", $e->getFile() . " on line " . $e->getLine() . "\n";
}
try {
    foo("C::foo");
} catch (Error $e) {
    echo "\n";
    do {
        echo "Exception: " . $e->getMessage() . "\n";
        $e = $e->getPrevious();
    } while ($e instanceof Error);
}
C::foo();
Пример #28
0
  <?php 
abstract class A
{
    public abstract function foo(int $x);
}
class B extends A
{
    public function foo(int $x)
    {
    }
}
class C extends B
{
    public function foo(array $x)
    {
    }
}
$o = new C();
$o->foo(array());
echo "OK\n";
Пример #29
0
{
    echo $str . "\n";
}
class Bar
{
    public function bar()
    {
        return "zing";
    }
    public function baz($other)
    {
        echo $this === $other ? "me\n" : "not me\n";
    }
    public function garply($n, $s, $b)
    {
        echo \hacklib_cast_as_boolean($b) ? $s : $n;
        echo "\n";
    }
}
class C
{
    public function foo($x)
    {
        other_func("and now: " . \hacklib_nullsafe($x)->bar());
        \hacklib_nullsafe($x)->baz($x);
        \hacklib_nullsafe($x)->garply(1, "hi", true);
    }
}
$c = new C();
$c->foo(new Bar());
$c->foo(null);
Пример #30
0
<?php

class C
{
    public static function foo()
    {
        return "world\n";
    }
    public static $foo = "hello";
}
echo C::$foo;
echo C::foo();