bar() public méthode

public bar ( )
Exemple #1
0
<?php

error_reporting(E_ALL);
class foo
{
    public function bar()
    {
        $x = array();
        $x[] = 3;
        $x[] = array(1, 5);
        $x[] = new foo();
        return $x;
    }
}
$foo = new foo();
var_dump($x = $foo->bar()[1]);
var_dump($foo->bar()[1][1]);
var_dump($x[0]);
var_dump($x = $foo->bar()[2]);
var_dump($x->bar());
var_dump($x->bar()[0]);
$x = array();
$x[] = new foo();
var_dump($x[0]->bar()[2]);
var_dump($foo->bar()[2]->bar()[1]);
var_dump($foo->bar()[2]->bar()[2]->bar()[1][0]);
var_dump($foo->bar()[2]->bar()[2]->bar()[1][0][1]);
var_dump($foo->bar()[2]->bar()[2]->bar()[4]);
var_dump($foo->bar()[3]->bar());
Exemple #2
0
<?php

namespace foobar;

class foo
{
    public function bar(self $a)
    {
    }
}
$foo = new foo();
$foo->bar($foo);
// Ok!
$foo->bar(new \stdclass());
// Error, ok!
[expect php]
[file]
<?php 
$f = 'c="foo"';
class foo
{
    const foobar = 1;
    public $pp = array('t' => null);
    function bar()
    {
        echo $this->t = 'f';
    }
    function __get($prop)
    {
        return $this->pp[$prop];
    }
    function __set($prop, $val)
    {
        echo "__set";
        $this->pp[$prop] = '';
    }
}
$f = new foo();
$f->bar();
?>
--EXPECT--
__setf
Exemple #4
0
[expect php]
[file]
<?php 
class foo
{
    function bar()
    {
        $args = func_get_args();
        foreach ($args as $arg) {
            echo $arg;
        }
    }
}
$x = new foo();
$x->bar('ahoj', 13);
<?php

class foo
{
    function bar()
    {
        print "Hey there!\n";
    }
}
foo::bar();
<?php

class foo
{
    public function bar() : callable
    {
        $test = "one";
        return function () use($test) : array {
            return null;
        };
    }
}
$baz = new foo();
var_dump($func = $baz->bar(), $func());
Exemple #7
0
<?php

final class foo
{
    public $bar;
    private $foo = 0;
    public function __construct($bar)
    {
        $this->bar = $bar;
    }
    public function foo()
    {
        return ++$this->foo;
    }
    public static function bar()
    {
        return new self(123);
    }
}
$foo = new foo('azerty');
echo $foo->foo() . "\n";
echo $foo->bar . "\n";
echo foo::bar()->bar . "\n";
<?php

class foo
{
    public function bar() : callable
    {
        $test = "one";
        return function () use($test) : array {
            return array($test);
        };
    }
}
$baz = new foo();
var_dump($baz->bar());
Exemple #9
0
    {
        $this->val = 1;
    }
    function bar()
    {
        echo $this->val;
        $ref =& $this;
        $ref->val = 2;
        echo $this->val;
        $ref2 = $this;
        $ref2->val = 3;
        echo $this->val;
        $x = new foo();
        echo $x->val;
        $ref3 =& $x;
        $ref3->val = 4;
        echo $x->val;
        $ref4 = $x;
        $ref4->val = 5;
        echo $x->val;
    }
    var $val;
}
$x = new foo();
$x->bar();
$ref5 = $x;
$ref5->val = 6;
echo $x->val;
$ref6 =& $x;
$ref6->val = 7;
echo $x->val;
Exemple #10
0
[expect php]
[file]
<?php 
function testfunc($var)
{
    echo "testfunc {$var}\n";
}
class foo
{
    public $arr = array('testfunc');
    function bar()
    {
        $this->arr[0]('testvalue');
    }
}
$a = new foo();
$a->bar();
Exemple #11
0
function main()
{
    $l = new foo();
    $l->bar();
}
Exemple #12
0
    function __construct()
    {
        echo "class ok\n";
    }
    static function bar()
    {
        return "method ok\n";
    }
}
function f1($x = namespace\C)
{
    return $x;
}
function f2($x = namespace\foo::C)
{
    return $x;
}
function f3(namespace\foo $x)
{
    return "ok\n";
}
echo namespace\C;
echo namespace\foo();
echo namespace\foo::C;
echo namespace\foo::C2;
echo namespace\foo::$var;
echo namespace\foo::bar();
echo namespace\f1();
echo namespace\f2();
echo namespace\f3(new namespace\foo());
echo namespace\unknown;
Exemple #13
0
<?php

class foo
{
    public $test = 0;
    private $test_2 = 1;
    protected $test_3 = 2;
    public function bar()
    {
        try {
            throw new Exception('foo');
        } catch (Exception $this) {
            var_dump($this);
        }
        $this->baz();
    }
    public function baz()
    {
        foreach ($this as $k => $v) {
            printf("'%s' => '%s'\n", $k, $v);
        }
        print "ok\n";
    }
}
$test = new foo();
$test->bar();
<?php

def_md('foo\\bar', 5, function () {
    echo '.';
    return "1\n";
});
def_md('foo::bar', 5, function () {
    echo '.';
    return "2\n";
});
echo foo\bar();
echo foo\bar();
echo foo::bar();
echo foo::bar();
?>
---
.1
1
.2
2
Exemple #15
0
--TEST--
Bug #27504 (call_user_func_array allows calling of private/protected methods)
--FILE--
<?php 
class foo
{
    function __construct()
    {
        $this->bar('1');
    }
    private function bar($param)
    {
        echo 'Called function foo:bar(' . $param . ')' . "\n";
    }
}
$foo = new foo();
call_user_func_array(array($foo, 'bar'), array('2'));
$foo->bar('3');
?>
--EXPECTF--
Called function foo:bar(1)
Warning: expects parameter 1 to be valid callback, cannot access in %s on line %d at pos %d

Fatal error: Call to private method foo::bar() from context '' in %s on line %d, position %d
Exemple #16
0
<?php

class foo extends RecursiveIteratorIterator
{
    public function __construct($str)
    {
    }
    public function bar()
    {
    }
}
$foo = new foo("This is bar");
echo $foo->bar();
?>
==DONE==
<?php 
exit(0);
Exemple #17
0
<?php

class foo
{
    function bar()
    {
        var_dump(get_class());
    }
}
class foo2 extends foo
{
}
foo::bar();
foo2::bar();
$f1 = new foo();
$f2 = new foo2();
$f1->bar();
$f2->bar();
var_dump(get_class());
var_dump(get_class("qwerty"));
var_dump(get_class($f1));
var_dump(get_class($f2));
echo "Done\n";
/**
 * @package test
 */
function dataProviderAnalyzerCalculatesExpectedCallCount17()
{
    foo::bar()->bar();
    f00::bar()->bar();
}
<?php

error_reporting(4095);
interface test
{
    public function bar();
}
class foo implements test
{
    public function bar($foo = NULL)
    {
        echo "foo\n";
    }
}
$foo = new foo();
$foo->bar();
Exemple #20
0
            static $c = 2;
            static $g;
            static $i;
            $e = 2;
        } else {
            static $d = 2;
            static $h;
            $f = 2;
        }
        echo foo::$a;
        echo foo::$b;
        echo foo::$c;
        echo foo::$d;
        echo foo::$e;
        echo foo::$f;
        echo $a;
        echo $b;
        echo $c;
        echo $d;
        echo $e;
        echo $f;
        echo $g;
        echo $h;
        echo $i;
    }
}
echo foo::$a;
echo foo::$b;
$v = new foo();
$v->bar();