|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-02-23 16:20 UTC] cmb@php.net
-Status: Open
+Status: Suspended
[2021-02-23 16:20 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 13:00:01 2025 UTC |
Description: ------------ Like static variables in C, there could be variables in PHP that are only locally available in an included file, but not available from outside. This way local variables would work like private properties in objects, but without the need of using all the ceremony of OOP. I'm not sure yet about the need of using the local keyword in functions defined in the included file. Test script: --------------- child.php <?php local $local_variable = 'a local variable in included module'; function local_function() { print "Local variables are visible in local functions ({$local_variable})."; } print "Our local variable is '{$local_variable}'."; local_function(); ?> mother.php <?php include('child.php'); print "child.php's local variable is '{$local_variable}'."; ?> Expected result: ---------------- Our local variable is 'a local variable in included module'. Local variables are visible in local functions (a local variable in included module). child.php's local variable is ''. Notice: Undefined variable: local_variable in mother.php on line 3 Actual result: -------------- Our local variable is 'a local variable in included module'. Notice: Undefined variable: local_variable in child.php on line 4 Local variables are visible in local functions (). child.php's local variable is 'a local variable in included module'.