php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26173 Global vs function scope problem?
Submitted: 2003-11-08 01:49 UTC Modified: 2003-11-08 01:53 UTC
From: myle34 at hotmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.0.0b2 (beta2) OS: Windows XP Home
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: myle34 at hotmail dot com
New email:
PHP Version: OS:

 

 [2003-11-08 01:49 UTC] myle34 at hotmail dot com
Description:
------------
I'm not sure if this is a bug, but I haven't found anything so far stating that it isn't so...

I am using Windows XP Home and Apache 2.0.47 with PHP beta 2.

Reproduce code:
---------------
// Uncommenting the following makes it work...
// global $foo;

$foo = 'bar';

// Uncommenting the following doesn't help...
// global $foo;

function Test()
{
  global $foo;

  echo $foo;
}

Expected result:
----------------
bar

Actual result:
--------------
No output

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-08 01:52 UTC] myle34 at hotmail dot com
sorry, forgot to call Test() at the bottom of the reproduce code... simply put in Test(); at the bottom.
 [2003-11-08 01:53 UTC] myle34 at hotmail dot com
Sorry, bad reporduce code....
 [2003-11-26 13:16 UTC] kharris at lhinfo dot com
I have a similar problem and here is the code I used to track it:

cfg file
<?php
 $gPlace = "http://www.lhinfo.com";
?>

run file
<?php
 include ( 'cfgfile.inc' );
 echo 'global space [' . $gPlace .];

 function testme ()
 {
   global $gPlace;
   
   echo 'testme [' . $gPlace . ']';
 }

 testme ();


Ouput:
global space [http://www.lhinfo.com]
testme []

I have even changed it to remove the config file and place the globals at the top of my file.  The same problem occurs.

Dumping $GLOBALS shows gPlace as a null string
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 20:01:31 2024 UTC