php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50364 global keyword doesn't work as expected
Submitted: 2009-12-02 20:36 UTC Modified: 2009-12-02 20:51 UTC
From: damp12000 at hotmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.11 OS: Linux
Private report: No CVE-ID: None
 [2009-12-02 20:36 UTC] damp12000 at hotmail dot com
Description:
------------
'global' keyword in a function does not work as expected when an file is included from within a function scope

Reproduce code:
---------------
file b1.php
<?
$a = '1';
doInclude();
function doInclude() {
    require('b2.php'); }
?>

file b2.php
<?
$b = '2';
testGlobalScope();
function testGlobalScope() {
	global $a,$b;
	print("$a\n$b\n");
}
?>

Expected result:
----------------
1
2

Actual result:
--------------
1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-02 20:51 UTC] derick@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

$b exists in doInclude's scope only, because that's where it's require'd in.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Dec 06 06:00:01 2025 UTC