Exemple #1
0
 public function barfunc()
 {
     // funcdef 1
     $x = new foo();
     // call 0
     $x->foofunc();
     // call 1
 }
 function bar()
 {
     print "calling foo statically:\n";
     foo::func();
     print "calling foo dynamically:\n";
     $foo = new foo();
     $foo->func();
     print "done\n";
 }
Exemple #3
0
 function foo($bla)
 {
     $array = array('key' => 'value', 'anotherKey' => 'anotherValue');
     echo 'foo';
     foo::foo($param1, $param2);
     $this->foo($param3, $param4);
     somefunc($param5, $param6);
 }
Exemple #4
0
 public function test()
 {
     call_user_func(array('FOO', 'ABC'));
     call_user_func(array($this, 'ABC'));
     foo::XYZ();
     self::WWW();
     call_user_func('FOO::ABC');
 }
Exemple #5
0
        echo "b = " . $this->b . "\n";
    }
    function mul()
    {
        return $this->a * $this->b;
    }
}
class bar extends foo
{
    public $c;
    function display()
    {
        /* alternative display function for class bar */
        echo "This is class bar\n";
        echo "a = " . $this->a . "\n";
        echo "b = " . $this->b . "\n";
        echo "c = " . $this->c . "\n";
    }
}
$foo1 = new foo();
$foo1->a = 2;
$foo1->b = 5;
$foo1->display();
echo $foo1->mul() . "\n";
echo "-----\n";
$bar1 = new bar();
$bar1->a = 4;
$bar1->b = 3;
$bar1->c = 12;
$bar1->display();
echo $bar1->mul() . "\n";
Exemple #6
0
    $d = 10;
    $d = func($a, $b);
    exit;
}
if ($which == 1) {
    /**
     * 返回引用示例1
     */
    class foo
    {
        public $value = 20;
        function &getValue()
        {
            return $this->value;
        }
    }
    $obj = new foo();
    $value =& $obj->getValue();
    // test 2:
    $obj->value = 30;
    echo $value;
    exit;
    // test 1:
    $value = 30;
    echo $obj->value;
    exit;
}
$a = '100';
$b =& $a;
$b = 200;
echo $a;
Exemple #7
0
<?php

class foo
{
    public $foo = 1;
    function as_string()
    {
        assert('$this->foo == 1');
    }
    function as_expr()
    {
        assert($this->foo == 1);
    }
}
$foo = new foo();
$foo->as_expr();
$foo->as_string();
{
    public $prop = 'a value';
    function foo($arg)
    {
        print "Constructor called on {$arg}\n";
    }
    function method()
    {
        print "Method called\n";
        return $this;
    }
    function method2()
    {
        print "Method 2 called\n";
        return $this;
    }
}
$foo = new foo('an argument');
$foo->method()->method();
// Can you do it on properties too?
print "property is :" . $foo->method()->prop . "\n";
$foo->method()->method2()->prop = 'newval';
print "property is :" . $foo->method()->method2()->prop . "\n";
// Don't forget the double-quoted string parser:
print "property is : {$foo->method()->prop}\n";
function afun()
{
    return new foo(22);
}
print afun()->prop;
print_r(afun()->method());
Exemple #9
0
<?php

class foo
{
    static $bar = 123;
    static function baz()
    {
        return 456;
    }
}
echo foo::$bar;
// will print 123
echo foo::baz();
// will print 456
    {
        echo "Bar::testPrivate\n";
    }
}
class Foo extends Bar
{
    public function testPublic()
    {
        echo "Foo::testPublic\n";
    }
    private function testPrivate()
    {
        echo "Foo::testPrivate\n";
    }
}
$myFoo = new foo();
$myFoo->test();
// Bar::testPrivate
// Foo::testPublic
/**
Объекты одного типа имеют доступ к элементам с модификаторами private и protected друг друга,
даже если не являются одним и тем же экземпляром. Это объясняется тем, что реализация видимости
элементов известна внутри этих объектов.

Пример #3 Доступ к элементам с модификатором private из объектов одного типа
*/
class Test
{
    private $foo;
    public function __construct($foo)
    {
Exemple #11
0
 public function teste()
 {
     return foo::x(function &($a = 1, $b) {
     });
 }
0000727 


instantiate a class based on a classname from an array

<?php 
class foo
{
    var $directive = array('columnClass' => 'bar');
    function makeOne()
    {
        //create a new tableDefinition object
        $columnDef =& new $this->directive['columnClass']();
        $columnDef->zot();
    }
}
class bar
{
    function zot()
    {
        echo "they've spotted us\n";
    }
}
$afoo = new foo();
$afoo->makeOne();
?>
 	
[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 #14
0
<?php

class foo
{
    public function __call($a, $b)
    {
        print "non-static - ok\n";
    }
    public static function __callstatic($a, $b)
    {
        print "static - ok\n";
    }
}
$a = new foo();
$a->foooo();
$a::foooo();
$b = 'aaaaa1';
$a->{$b}();
$a::$b();
$b = '  ';
$a->{$b}();
$a::$b();
$b = str_repeat('a', 10000);
$a->{$b}();
$a::$b();
$b = NULL;
$a->{$b}();
Exemple #15
0
 public function __contruct()
 {
     parent::__construct();
 }
Exemple #16
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";
Exemple #17
0
 function &a($arg)
 {
     return parent::a($arg);
 }
Exemple #18
0
function t()
{
    $x = 1;
    foo::ioo($x, $y);
}
Exemple #19
0
$bing = new zot();
//$bing = new zot("asdf");
$bing->afun(34);
zot();
$bing = new argconstructor(12);
$bing->afun(12);
$c = 'argconstructor';
$bap = new $c();
$bpa = new $c(12);
class bar
{
    var $baz;
    function bar($a = 'noarg')
    {
        $this->baz = $a;
    }
}
class foo
{
    var $a = 'bar';
    function assign()
    {
        $zap = new $this->a('setbaz');
        print_r($zap);
        $zap2 = new $this->a();
        print_r($zap);
    }
}
$a = new foo();
$a->assign();
print_r($a);
 function inc()
 {
     self::$p7 = 20;
 }
unable to foreach on a class variable
parse error on this code in a class method:

foreach ($this->attributes as $attrKey => $attrVal) {

<?php 
class foo
{
    var $attributes = array(1 => "Foo", 2 => "Bar");
    function zot()
    {
        foreach ($this->attributes as $attrKey => $attrVal) {
            print "{$attrKey}, {$attrVal}\n";
        }
    }
}
$afoo = new foo();
$afoo->zot();
Exemple #22
0
class bar extends foo
{
    function test_bar()
    {
        var_dump(get_parent_class());
    }
}
class goo extends bar
{
    function test_goo()
    {
        var_dump(get_parent_class());
    }
}
$bar = new bar();
$foo = new foo();
$goo = new goo();
$foo->test();
$bar->test();
$bar->test_bar();
$goo->test();
$goo->test_bar();
$goo->test_goo();
var_dump(get_parent_class($bar));
var_dump(get_parent_class($foo));
var_dump(get_parent_class($goo));
var_dump(get_parent_class("bar"));
var_dump(get_parent_class("foo"));
var_dump(get_parent_class("goo"));
var_dump(get_parent_class("i"));
var_dump(get_parent_class(""));
<?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 #24
0
<?php

require_once '../../includes/header.php';
?>
<pre>
<?php 
echo "Object Initialization\n";
class foo
{
    function do_foo()
    {
        echo "Doing foo.";
    }
}
$bar = new foo();
$bar->do_foo();
echo "Converting to object\n";
$obj = (object) 'ciao';
echo $obj->scalar;
// outputs 'ciao'
?>
</pre>
<?php 
require_once '../../includes/footer.php';
<?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 #26
0
            print "HERE\n";
        } catch (LocalNonException $e) {
            print "HERE\n";
        } catch (UndefinedClass $e) {
            print "HERE\n";
        } catch (OutOfBoundsException $e) {
            print "HERE\n";
        } catch (\OutOfBoundsException $e) {
            print "HERE\n";
        }
    }
}
class LocalException extends \Exception
{
}
class LocalSubException extends LocalException
{
}
class LocalSubSubException extends LocalSubException
{
}
class LocalNonException
{
}
function something_that_might_break()
{
    print __METHOD__;
    throw new \Exception('a,a,');
}
$f = new foo();
$f->test();
<?php

/**
 * samebug-notifier-php - index.php
 */
/** Include files.
 */
require 'src/Samebug/SamebugClient.php';
require 'src/Samebug/SamebugRecorder.php';
require 'src/Samebug/SamebugRecorderConnectorCurl.php';
/** Create samebug client.
 * @var \Samebug\SamebugClient $client
 */
$client = new \Samebug\SamebugClient('your_api_key');
$client->attach();
class foo
{
    function div($a, $b)
    {
        return $a / $b;
    }
}
$bar = new foo();
$c = $bar->div(2, 0);
var_dump($c);
Exemple #28
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 #29
0
<?php

error_reporting(E_ALL);
class foo
{
    public $bar = "ok";
    function method()
    {
        $this->yes = "done";
    }
}
$baz = new foo();
$baz->method();
$arr[3] = new foo();
$arr[3]->method();
session_start();
$_SESSION["baz"] = $baz;
$_SESSION["arr"] = $arr;
var_dump(session_encode());
session_destroy();
Exemple #30
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