php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30888 wrong access to global arrays
Submitted: 2004-11-24 22:00 UTC Modified: 2004-11-24 22:13 UTC
From: bugz at nagash dot org Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.2 OS: FreeBSD \ Linux \ windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bugz at nagash dot org
New email:
PHP Version: OS:

 

 [2004-11-24 22:00 UTC] bugz at nagash dot org
Description:
------------
don't work in the class - but if I do the same action NOT IN THE CLASS METHOD - it works


<form action="test.php" method="post">
<input type="text" name="name" />
<input type="submit" />
</form>
<?php
error_reporting (E_ALL); 
if (!empty($_POST['name'])) {
$z = '_POST';
echo ${$z}['name'];
}
?>

this works fine

Reproduce code:
---------------
<form action="test.php" method="post">
<input type="text" name="name" />
<input type="submit" />
</form>
<?php
error_reporting (E_ALL); 
if (!empty($_POST['name'])) {
	class blah {
		function tester () {
			$z = '_POST';
			echo ${$z}['name'];
		}
	}
	$a = new blah;
	$a->tester();
}
?>

Expected result:
----------------
the value I wrote in the form

Actual result:
--------------
Notice: Undefined variable: _POST in /home/nagash/www/test.php on line 11


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-24 22:10 UTC] bugz at nagash dot org
sorry.
http://ru2.php.net/en/language.variables.predefined
Variable variables: Superglobals cannot be used as variable variables inside functions or class methods.
 [2004-11-24 22:13 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You can not use the superglobals with variable-variables.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Nov 22 12:00:02 2025 UTC