php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52793 Output of example code at documention is not as described
Submitted: 2010-09-07 16:22 UTC Modified: 2010-09-08 12:19 UTC
From: jurciks66 at inbox dot lv Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: Linux
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: jurciks66 at inbox dot lv
New email:
PHP Version: OS:

 

 [2010-09-07 16:22 UTC] jurciks66 at inbox dot lv
Description:
------------
Copy and run code from manual about $GLOBALS (http://php.net/manual/en/reserved.variables.globals.php)

Actual output is: 

$foo in global scope: 
$foo in current scope: local variable


Expected result:
----------------
I`m expecting to see the same output as seen on documentation page


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-07 16:26 UTC] rquadling@php.net
-Status: Open +Status: Bogus
 [2010-09-07 16:26 UTC] rquadling@php.net
[2010/09/07 15:23:31] [Z:\] [\\richardquadling\scratch$ ] >php
<?php
function test() {
    $foo = "local variable";

    echo '$foo in global scope: ' . $GLOBALS["foo"] . "\n";
    echo '$foo in current scope: ' . $foo . "\n";
}

$foo = "Example content";
test();
?>
^Z
$foo in global scope: Example content
$foo in current scope: local variable

Code and example output agree.
 [2010-09-08 10:43 UTC] jurciks66 at inbox dot lv
well, sorry about wrong problem description. my test file was parsed by another file, so, actual test script would look like this - 

<?php

	function test2() {
		function test() {
		    $foo = "local variable";

		    echo '$foo in global scope: ' . $GLOBALS["foo"] . "\n";
		    echo '$foo in current scope: ' . $foo . "\n";
		}

		$foo = "Example content";
		test();
	}

	test2();
?>

So I`m still wondering why my output is -

$foo in global scope: 
$foo in current scope: local variable
 [2010-09-08 12:19 UTC] rquadling@php.net
The bug system is not a support channel.

If you need support please contact the appropriate mailing lists via 
http://www.php.net/mailing-lists.php

Specifically to answer your question, please read about variable scope : 
http://docs.php.net/manual/en/language.variables.scope.php
 [2010-09-08 13:20 UTC] jurciks66 at inbox dot lv
Thanks for your time and sorry for the trouble
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 18:01:32 2025 UTC