php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15805 Use undefined global variable in function - not warning
Submitted: 2002-03-01 03:10 UTC Modified: 2002-03-01 03:37 UTC
From: Vladimir dot Michl at hlubocky dot del dot cz Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.1.1 OS: Windows 2000
Private report: No CVE-ID: None
 [2002-03-01 03:10 UTC] Vladimir dot Michl at hlubocky dot del dot cz
I try use global variable in function. When variable is not defined and I have set error_reporting to E_ALL, PHP doesn't
report, that variable is not defined, but silently define it.

<?php
// Test for use global variable if variable not defined.
// PHP don't write any warning

ini_set("error_reporting", E_ALL);

function test_me(){
	global $test_var;
	return $test_var;
};

// Next line report message "Undefined variable..." - It's ok.
echo "Following message 'Undefined variable...' is OK! It's feature.\n";
echo "Test var (direct test_var): ".$test_var."\n";

// Next line DOESN'T report message "Undefined variable" - It's bug?
echo "Is after this message, message about 'Undefined variable...'? If not - PHP bug\n";
echo "Test var (test_me): ".test_me()."\n";

// Next line DOESN'T report message "Undefined variable" - It's bug?
echo "Test var (direct test_var): ".$test_var."\n";

echo "Now defining test_var\n";
$test_var = "I am here!";
echo "Test var (test_me): ".test_me()."\n";

?>

Is this problem known?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-01 03:37 UTC] sander@php.net
Expected behaviour. Global defines that variable.
 [2002-03-04 03:23 UTC] Vladimir dot Michl at hlubocky dot del dot cz
OK, command global may define variable, but if global variable that name is not defined, PHP write this to output
(if E_NOTICE is enabled). Without this debugging code from example is dificult.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 04 04:01:29 2025 UTC