parent
da93efcb69
commit
fe99467ea4
4 changed files with 155 additions and 0 deletions
@ -0,0 +1,34 @@ |
|||||||
|
--TEST-- |
||||||
|
Function returning by reference can forward another by-reference call |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
function main() |
||||||
|
{ |
||||||
|
$value1 = test1(); |
||||||
|
var_dump($value1); |
||||||
|
$value2 = &test1(); |
||||||
|
var_dump($value2); |
||||||
|
$value2 = 0; |
||||||
|
$value3 = test1(); |
||||||
|
var_dump($value3); |
||||||
|
} |
||||||
|
|
||||||
|
function &test1() |
||||||
|
{ |
||||||
|
return test2(); |
||||||
|
} |
||||||
|
|
||||||
|
function &test2() |
||||||
|
{ |
||||||
|
global $value; |
||||||
|
$value++; |
||||||
|
return $value; |
||||||
|
} |
||||||
|
|
||||||
|
// main(); |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
int(1) |
||||||
|
int(2) |
||||||
|
int(1) |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
--TEST-- |
||||||
|
Method returning by reference can forward another by-reference method call |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class Test |
||||||
|
{ |
||||||
|
private $value = 1; |
||||||
|
|
||||||
|
public function &getValue() |
||||||
|
{ |
||||||
|
return $this->value; |
||||||
|
} |
||||||
|
|
||||||
|
public function &getRefValue() |
||||||
|
{ |
||||||
|
return $this->getValue(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main() |
||||||
|
{ |
||||||
|
$test = new Test; |
||||||
|
var_dump($test->getRefValue()); |
||||||
|
$ref = &$test->getRefValue(); |
||||||
|
$ref = 2; |
||||||
|
var_dump($test->getValue()); |
||||||
|
} |
||||||
|
|
||||||
|
// main(); |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
int(1) |
||||||
|
int(2) |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
--TEST-- |
||||||
|
Static method returning by reference can forward another by-reference static call |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class Counter |
||||||
|
{ |
||||||
|
private static $value = 0; |
||||||
|
|
||||||
|
public static function &next() |
||||||
|
{ |
||||||
|
self::$value++; |
||||||
|
return self::$value; |
||||||
|
} |
||||||
|
|
||||||
|
public static function ¤t() |
||||||
|
{ |
||||||
|
return self::next(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main() |
||||||
|
{ |
||||||
|
var_dump(Counter::current()); |
||||||
|
$ref = &Counter::current(); |
||||||
|
$ref = 10; |
||||||
|
var_dump(Counter::next()); |
||||||
|
} |
||||||
|
|
||||||
|
// main(); |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
int(1) |
||||||
|
int(11) |
||||||
Loading…
Reference in new issue