Bug #79025 [Com]: Assigning superglobals by reference in functions are reset to null

From: Date: Tue, 24 Dec 2019 05:46:41 +0000
Subject: Bug #79025 [Com]: Assigning superglobals by reference in functions are reset to null
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224505@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79025&edit=1 ID: 79025 Comment by: thedinosaurmail at gmail dot com Reported by: ssigwart at yahoo dot com Summary: Assigning superglobals by reference in functions are reset to null Status: Open Type: Bug Package: *General Issues Operating System: Any PHP Version: 7.4.1 Block user comment: N Private report: N New Comment: https://3v4l.org/WGsD9 it seems same at ervery version Previous Comments: ------------------------------------------------------------------------ [2019-12-24 05:19:33] ssigwart at yahoo dot com Description: ------------ When you assign a variable to a superglobal ($_SESSION, $_GET, etc) by reference within a function, the variable is reset to null once you exit the function. Test script: --------------- $_SESSION['var'] = 1; function func1() { global $ref; global $nonRef; $ref = &$_SESSION['var']; $nonRef = $_SESSION['var']; } func1(); var_dump($_SESSION['var']); var_dump($ref); var_dump($nonRef); Expected result: ---------------- int(1) int(1) int(1) Actual result: -------------- int(1) NULL int(1) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79025&edit=1

« previous php.bugs (#224505) next »