Esempio n. 1
0
 public function testInvoke()
 {
     $result = invoke(function () {
         return true;
     });
     $this->assertTrue($result);
     $this->assertTrue(is_float(collector()));
 }
Esempio n. 2
0
function &getRef()
{
    global $c;
    return $c;
}
$c1 =& getRef();
$c1++;
var_dump($c);
// 6
var_dump($c1);
// 6
function &collector()
{
    static $collection = array();
    return $collection;
}
array_push(collector(), 'foo');
//array_push(&collector(), 'foo'); // fatal
var_dump(collector());
// foo is inside
function func(&$arraykey)
{
    return $arraykey;
}
$array = array('a', 'b', 'c');
foreach (array_keys($array) as $key) {
    $y =& func($array[$key]);
    $z[] =& $y;
}
var_dump($z);
// c, c, c
{
    $s = serialize($data);
    $ref = [];
    return $ref;
}
function &collector()
{
    static $sample = array(1);
    return $sample;
}
$exit = array('goo' => 'glé', 'fileres' => fopen(__FILE__, 'r'));
$sample =& collector();
$sample[] = 2;
$sample[] =& $exit;
$sample[2]["huhu"] = 123;
$sample[2]["igrio"] =& collector();
$sample[2]["closureExample"] = function () {
};
$sample[3] = new stdclass();
$sample[3]->bla = "jkljjl";
$sample[3]->test =& $exit;
$sample[3]->bli = "jkl\"i" . chr(0) . "jjl";
$sample[4] = new stdclass();
$sample[4]->foo = new Foo();
if (class_exists('SoapClient')) {
    $soap = $sample[4]->soap = new SoapClient('http://www.webservicex.net/geoipservice.asmx?WSDL');
    try {
        $sample[4]->soapRequest = $soap->__soapCall("GetGeoIPSoapIn", ["IPAddress" => "31.187.70.14"]);
    } catch (Exception $e) {
        // $sample[4]->soapError = $e;
    }
Esempio n. 4
0
        return $this->value;
    }
}
$obj = new foo();
$myValue =& $obj->getValue();
// $myValue is a reference to $obj->value, which is 42.
$obj->value = 2;
echo $myValue . "\n";
// prints the new value of $obj->value, i.e. 2.
//To use the returned reference, you must use reference assigment:
function &collector()
{
    static $collection = array();
    return $collection;
}
$collection =& collector();
//you must use reference assigment
$collection[] = 'foo';
var_dump($collection);
//To pass the returned reference to another function expecting a reference you can use this syntax:
function &collector2()
{
    static $collection2 = array();
    return $collection2;
}
$coll2 = array_push(collector2(), 'foo');
var_dump($coll2);
//1
//Note that array_push(&collector(), 'foo'); will not work, it results in a fatal error.
?>
</pre>