php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75743 ${$<superglobal variable>} inside function does not work
Submitted: 2017-12-28 13:31 UTC Modified: 2018-01-02 13:10 UTC
From: works dot devel at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.1.12 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: works dot devel at gmail dot com
New email:
PHP Version: OS:

 

 [2017-12-28 13:31 UTC] works dot devel at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/reserved.variables.get
---

function f() {
    $var = '_GET';
    print_r(${$var});
}
f();


Test script:
---------------
http://localhost/my-script.php?foo=bar

Expected result:
----------------
Array ( foo => bar )

Actual result:
--------------
Notice: Undefined variable: _GET in ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-28 13:47 UTC] danack@php.net
I'm not sure the reason, but this is defined behaviour http://php.net/manual/en/language.variables.superglobals.php: 

Note: Variable variables
Superglobals cannot be used as variable variables inside functions or class methods.
 [2018-01-02 13:10 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: Arrays related +Package: Scripting Engine problem -Assigned To: +Assigned To: cmb
 [2018-01-02 13:10 UTC] cmb@php.net
Since the behavior is documented as such, this is not a bug.

Changing the current behavior would require an RFC.  Feel free to
start the process[1]. :)

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 13:00:02 2026 UTC