php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6191 Can't return global variable when defined with a dynamic name using eval
Submitted: 2000-08-15 22:21 UTC Modified: 2000-08-16 02:54 UTC
From: smaug at thegame dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.1pl2 OS: Windows 2000 Pro / Apache 1.3.12
Private report: No CVE-ID: None
 [2000-08-15 22:21 UTC] smaug at thegame dot com
this doesn't work:

function _global($___name) {
	eval('global $' . $___name . ';');
	eval('return $' . $___name . ';');
}


this version does:

function _global($___name) {
	eval('global $' . $___name . ';');
	eval('$___temp = $' . $___name . ';');
	return $___temp;
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-16 02:54 UTC] hholzgra@php.net
a return in an eval() returns from the eval() itself,
not from the calling function

this would do:

function _global($___name) {
   eval('global $' . $___name . ';');
   return eval('return $' . $___name . ';');
}

 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Oct 11 08:00:01 2026 UTC