php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34689 Inconsistent handling of $GLOBALS from included files
Submitted: 2005-09-30 12:26 UTC Modified: 2005-09-30 12:42 UTC
From: sebastian@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.0-CVS OS: *
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: sebastian@php.net
New email:
PHP Version: OS:

 

 [2005-09-30 12:26 UTC] sebastian@php.net
Description:
------------
test.php

  <?php
  include_once 'foo.php';
  var_dump($GLOBALS['foo']);
  ?>

foo.php

  <?php
  $foo = 'bar';
  ?>

Output

  string(3) "bar"


test.php

  <?php
  class PHPUnit2_Util_Fileloader {
      public static function checkAndLoad($filename) {
          include_once $filename;
      }
  }

  PHPUnit2_Util_Fileloader::checkAndLoad('foo.php');
  var_dump($GLOBALS['foo']);
  ?>

foo.php

  <?php
  $foo = 'bar';
  ?>

Output

  NULL


test.php

  <?php
  class PHPUnit2_Util_Fileloader {
      public static function checkAndLoad($filename) {
          include_once $filename;
      }
  }

  PHPUnit2_Util_Fileloader::checkAndLoad('foo.php');
  var_dump($GLOBALS['foo']);
  ?>

foo.php

  <?php
  $GLOBALS['foo'] = 'bar';
  ?>

Output

  string(3) "bar"

Reproduce code:
---------------
test.php

  <?php
  class PHPUnit2_Util_Fileloader {
      public static function checkAndLoad($filename) {
          include_once $filename;
      }
  }

  PHPUnit2_Util_Fileloader::checkAndLoad('foo.php');
  var_dump($GLOBALS['foo']);
  ?>

foo.php

  <?php
  $foo = 'bar';
  ?>

Expected result:
----------------
string(3) "bar"

Actual result:
--------------
NULL

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-30 12:28 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-09-30 12:29 UTC] sebastian@php.net
I am using CVS (current PHP_5_1).
 [2005-09-30 12:36 UTC] tony2001@php.net
Sebastian, why they should become globals if you declare them inside a function?
 [2005-09-30 12:42 UTC] sebastian@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're right, Jani. Seems like the PHPUnit bug report that got me into this had me confused.

Thank you for your time and setting my head straight :-)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 09:01:31 2024 UTC