|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-04-11 21:02 UTC] djneoform at gmail dot com
Description:
------------
If you pass a variable by reference in a function, then within the function assign that variable a reference to another variable, the variable's reference gets overwritten and the variable (when the function ends) contains null.
Reproduce code:
---------------
$GLOBALS['glob_var'] = 10;
$var = funk($ref_var);
echo 'SHOULD BE 10: '.$var;
function funk(&$ref_var)
{
$ref_var = &$GLOBALS['glob_var'];
}
Expected result:
----------------
> SHOULD BE 10: 10
Actual result:
--------------
> SHOULD BE 10:
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 13:00:02 2025 UTC |
I made a mistake in the sample code, should read like this: $GLOBALS['glob_var'] = 10; funk($var); echo 'SHOULD BE 10: '.$var; function funk(&$ref_var) { $ref_var = &$GLOBALS['glob_var']; }