Req #69392 [Opn->Sus]: Local variable scope in included files
Edit report at https://bugs.php.net/bug.php?id=69392&edit=1
ID: 69392
Updated by: cmb@php.net
Reported by: gaborca at webvision dot hu
Summary: Local variable scope in included files
-Status: Open
+Status: Suspended
Type: Feature/Change Request
Package: Variables related
Operating System: Any
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
This feature request requires discussion for what this bug tracker
is not suitable. Please pursue the RFC process[1]. For the time
being, I'm suspending this ticket.
[1] <https://wiki.php.net/rfc/howto>
Previous Comments:
------------------------------------------------------------------------
[2015-04-07 10:28:27] gaborca at webvision dot hu
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'.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69392&edit=1
Thread (2 messages)