php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51840 definitions of global varaibles not working properly
Submitted: 2010-05-17 16:51 UTC Modified: 2010-05-17 16:56 UTC
From: christian dot gnoth at arcor dot de Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.2.13 OS: Linux x86_64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: christian dot gnoth at arcor dot de
New email:
PHP Version: OS:

 

 [2010-05-17 16:51 UTC] christian dot gnoth at arcor dot de
Description:
------------
hi,

I would like to define few variables global so that I can use them in all functions - also if I include a php file with functions.

actually I expect, that if I declare a variable outside the functions as global, that those variables are available inside the functions.

Test script:
---------------
global $var1;

function funct1()
{
  echo $var1;
}


include 'incl_file1';

incl_dile1:
function funct2()
{
  echo $var1;
}


Expected result:
----------------
should work without problem or notice that var1 is not defined...


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-17 16:56 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-05-17 16:56 UTC] johannes@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

Please re-read the chapter how scoping works in PHP.
http://php.net/manual/en/language.variables.scope.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Aug 13 13:00:03 2025 UTC