- Create new test file return-by-ref-method.phpt - Add test class with private value property - Implement getValue method returning copy of value - Implement getRefValue method returning reference to value - Test both regular and reference return behaviors - Verify reference assignment modifies original value - Add expected output with proper integer dumpspull/16/head
parent
2503c79f03
commit
f9c6abbbf9
1 changed files with 34 additions and 0 deletions
@ -0,0 +1,34 @@ |
||||
--TEST-- |
||||
Return value by reference (method) |
||||
--FILE-- |
||||
<?php |
||||
class Test |
||||
{ |
||||
private $value = 1; |
||||
|
||||
public function getValue() |
||||
{ |
||||
return $this->value; |
||||
} |
||||
|
||||
public function &getRefValue() |
||||
{ |
||||
return $this->value; |
||||
} |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$test = new Test; |
||||
var_dump($test->getValue()); |
||||
var_dump($refValue = &$test->getRefValue()); |
||||
$refValue = 2; |
||||
var_dump($test->getValue()); |
||||
var_dump($test->getRefValue()); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
int(1) |
||||
int(1) |
||||
int(2) |
||||
int(2) |
||||
Loading…
Reference in new issue