php / php/doc-en

Undefined variable variable $GLOBALS

Open
#3,142 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

Description

The following code:

<?php

$variable = 'GLOBALS';

$GLOBALS['GLOBALS'] = 'value';

var_dump($GLOBALS);

https://3v4l.org/lpfq6

Resulted in this output:

array(8) {
  ["_GET"]=>
  array(0) {
  }
  ["_POST"]=>
...
}

But I expected this output instead:

string(5) "value"

The global variable GLOBALS shouldn't be allowed because it's hidden behind the superglobal.

Another problem with this superglobal:
Calling $variable = 'GLOBALS';$$variable; outputs Warning: Undefined variable $GLOBALS, but that's not what the user expects, because $GLOBALS is available. I know it's stated in documentation that superglobal array is not allowed, but this error message could be less confusing.
https://www.php.net/manual/en/language.variables.variable.php

PHP Version

PHP 8.4

Operating System

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PHP manual page on variable variables linked in the issue and compare its explanation of superglobals with the PHP 8.4 examples provided. Done means the documentation accurately explains the $GLOBALS behavior and the potentially confusing undefined-variable warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.