|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-11-07 18:19 UTC] n8grndr1087 at optonline dot net
[2010-12-17 12:13 UTC] jani@php.net
-Package: Feature/Change Request
+Package: Scripting Engine problem
-Operating System: Unix
+Operating System: *
-PHP Version: 5.2.11
+PHP Version: *
[2012-08-11 17:44 UTC] youdontneedme at o2 dot pl
[2018-07-08 19:38 UTC] cmb@php.net
-Status: Open
+Status: Verified
-Type: Feature/Change Request
+Type: Documentation Problem
[2018-07-08 19:38 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 20 23:00:01 2025 UTC |
Description: ------------ Global variables should be able to be declared 'static'. Static globals, like in C, would only be accessible from the current file's scope. This would be a good way to protect internal variables used behind the scenes in a particular file. If there is any effective way to protect variables that I overlooked, outside of PHP classes, let me know. I understand that the possibility of this depends on how the include/file processing mechanism works. Reproduce code: --------------- myvar.inc: <?php static $myvar = 1; function get_myvar() { global $myvar; // Since its not a true global, this may be different return $myvar; } function set_myvar($v) { global $myvar; $myvar = $v; } ?> test.php: <?php include('myvar.inc'); echo get_myvar().'<br/>'; set_myvar(0); $myvar = 10000; echo get_myvar(); ?> Expected result: ---------------- 1 0 Actual result: -------------- 1 10000