1
0
mirror of https://github.com/php/php-src.git synced 2026-04-22 23:48:14 +02:00
Files
archived-php-src/tests/lang/passByReference_010.phpt
T
Dmitry Stogov 64b40f69dc Make ASSIGN, ASSIGN_OP, INC and DEC opcodes to return IS_TMP_VAR instead of IS_VAR.
This helps to avoid unnecessary IS_REFERENCE checks.
This changes some notices "Only variables should be passed by reference" to exception "Cannot pass parameter %d by reference".

Also, for consistency, compile-time fatal error "Only variables can be passed by reference" was converted to exception "Cannot pass parameter %d by reference"
2020-02-07 13:36:52 +03:00

67 lines
1.3 KiB
PHP

--TEST--
Passing assignments by reference
--FILE--
<?php
function f(&$a) {
var_dump($a);
$a = "a.changed";
}
echo "\n\n---> Pass constant assignment by reference:\n";
try {
f($a="a.original");
var_dump($a);
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() ."\n";
}
echo "\n\n---> Pass variable assignment by reference:\n";
try {
unset($a);
$a = "a.original";
f($b = $a);
var_dump($a);
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() ."\n";
}
echo "\n\n---> Pass reference assignment by reference:\n";
try {
unset($a, $b);
$a = "a.original";
f($b =& $a);
var_dump($a);
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() ."\n";
}
echo "\n\n---> Pass concat assignment by reference:\n";
try {
unset($a, $b);
$b = "b.original";
$a = "a.original";
f($b .= $a);
var_dump($a);
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() ."\n";
}
?>
--EXPECT--
---> Pass constant assignment by reference:
Exception: Cannot pass parameter 1 by reference
---> Pass variable assignment by reference:
Exception: Cannot pass parameter 1 by reference
---> Pass reference assignment by reference:
string(10) "a.original"
string(9) "a.changed"
---> Pass concat assignment by reference:
Exception: Cannot pass parameter 1 by reference