- Implement handling of MethodCall expressions in assignment operations with references - Add StaticCall expression support for reference assignments with proper name validation - Introduce native method lookup and reference return validation for method calls - Add static method reference assignment with class name resolution and parent/self handling - Update function return by reference to support property fetches and chained expressions - Modify documentation to reflect updated reference assignment capabilities - Add comprehensive tests for method and static call reference return scenariospull/16/head
parent
128bfa7e85
commit
2503c79f03
6 changed files with 184 additions and 21 deletions
@ -0,0 +1,6 @@ |
||||
<?php |
||||
$requireMethodAlias =& $GLOBALS['eval_box']->valueRef(); |
||||
$requireMethodAlias = 'method require'; |
||||
$requireStaticAlias =& RefBox::staticRef(); |
||||
$requireStaticAlias = 'static require'; |
||||
?> |
||||
@ -0,0 +1,87 @@ |
||||
--TEST-- |
||||
methods returning by reference preserve aliases |
||||
--FILE-- |
||||
<?php |
||||
class RefBox |
||||
{ |
||||
public $value = 1; |
||||
public static $staticValue = 10; |
||||
|
||||
public function &valueRef() |
||||
{ |
||||
return $this->value; |
||||
} |
||||
|
||||
public static function &staticRef() |
||||
{ |
||||
return self::$staticValue; |
||||
} |
||||
|
||||
public function valueCopy() |
||||
{ |
||||
return $this->value; |
||||
} |
||||
|
||||
public static function staticCopy() |
||||
{ |
||||
return self::$staticValue; |
||||
} |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$box = new RefBox(); |
||||
|
||||
$methodAlias =& $box->valueRef(); |
||||
$methodAlias = 42; |
||||
var_dump($box->valueRef()); |
||||
|
||||
$staticAlias =& RefBox::staticRef(); |
||||
$staticAlias = 77; |
||||
var_dump(RefBox::staticRef()); |
||||
|
||||
$GLOBALS['eval_box'] = $box; |
||||
eval('$evalMethodAlias =& $GLOBALS["eval_box"]->valueRef(); $evalMethodAlias = "method eval"; $evalStaticAlias =& RefBox::staticRef(); $evalStaticAlias = "static eval";'); |
||||
var_dump($box->valueRef()); |
||||
var_dump(RefBox::staticRef()); |
||||
|
||||
require __DIR__ . '/method-return-reference-require.inc'; |
||||
var_dump($box->valueRef()); |
||||
var_dump(RefBox::staticRef()); |
||||
|
||||
$method = 'valueRef'; |
||||
$dynamicMethodAlias =& $box->$method(); |
||||
$dynamicMethodAlias = 'method dynamic'; |
||||
var_dump($box->valueRef()); |
||||
|
||||
$staticMethod = 'staticRef'; |
||||
$dynamicStaticAlias =& RefBox::$staticMethod(); |
||||
$dynamicStaticAlias = 'static dynamic'; |
||||
var_dump(RefBox::staticRef()); |
||||
|
||||
$method = 'valueCopy'; |
||||
try { |
||||
$badMethodAlias =& $box->$method(); |
||||
} catch (TypeError $e) { |
||||
echo "dynamic method TypeError\n"; |
||||
} |
||||
|
||||
$staticMethod = 'staticCopy'; |
||||
try { |
||||
$badStaticAlias =& RefBox::$staticMethod(); |
||||
} catch (TypeError $e) { |
||||
echo "dynamic static TypeError\n"; |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
int(42) |
||||
int(77) |
||||
string(11) "method eval" |
||||
string(11) "static eval" |
||||
string(14) "method require" |
||||
string(14) "static require" |
||||
string(14) "method dynamic" |
||||
string(14) "static dynamic" |
||||
dynamic method TypeError |
||||
dynamic static TypeError |
||||
Loading…
Reference in new issue