php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #15202 not a bug, but new feature request
Submitted: 2002-01-24 06:20 UTC Modified: 2002-02-24 06:44 UTC
From: joyeux at 1984 dot cz Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.1.1 OS: Linux
Private report: No CVE-ID: None
 [2002-01-24 06:20 UTC] joyeux at 1984 dot cz
Using "global" is very unfriendly (you have many of them and have to declare them everytime and everywhere).
You change something and a mess is rising.

I have this idea:

<?

global $foo;
$foo="hello";

function a() {
  echo($foo);
}

?>

Today "global" located in the root do nothing. By my idea it should be "an absolute global" like $GLOBALS.
 Then you will be able to use this variable everywhere without defining it by global everytime.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-24 07:11 UTC] hholzgra@php.net
global variables are evil ;)

no, serious, it would be hard to track down 
if statements outside of a function 
(maybe in a totaly different file)
could affect the scope of variables inside
a function

either stay with global declarations or
make use of the special $GLOABLS array

or even better: try to design your code
so that it doesn't rely on globals at all
(the global declaration for functions 
was invented for a reason)

some keywords: side effects, reentrancy,
thread safety (not a php issue yet),
obfuscation ...
 [2002-01-24 21:54 UTC] yohgaki@php.net
I agree with hholzgra.
Mark this as bogus. Ok?
 [2002-02-24 03:37 UTC] roberto at berto dot net
$GLOBALS will make my code bigger than what joyeux suggested.
 [2002-02-24 06:44 UTC] derick@php.net
I've to agree with both Hartmut and Yasuo here: Globals are evil. And another thing, we cannot change this behavior anymore, it will break too many scripts.

Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 18:01:35 2024 UTC