Jump to content

Archived

This topic is now archived and is closed to further replies.

knowNothing

Nested variable scope

Recommended Posts

Lets say I've got a variable named $myvar in an included file inc.php.  If I want to use that variable in a function thats nested multiple times, must I pass it through explicity all the way down to the function that will use it?  In this case, I do not want to set it as a global.  And I'm not looking to use a class. Is this the only way to do it?  Or am I missing something that's gonna make me feel retarded?  Also, is there some kind of advanced variable scope tutorial out there?  At least more advanced than all the basic ones I keep reading?

[code]
<?php
  include ('inc.php');
 
  function myfunc1($myvar) {
      function myfunc2($myvar) {
        function myfunc3($myvar) {
            echo $myvar;
        }
      }
  }

?>
[/code]

Share this post


Link to post
Share on other sites
Some help please, I have a similar issue (first post).  I am trying to modify some files that have the following simplified structure

[code]
<?php
include 'a.inc';
include 'b.inc';
?>

a.inc has the following struture
<?php
"A form for user input"
include 'A1.inc';
include 'A2.inc';
?>

A1.inc has the following struture
<?php
function 1 {
$x = "Value from user input form"
}
?>

A2.inc has the following struture
<?php
function 2 {
$y = $x + 1
}
include 'A2_1.inc';
?>

A2_1.inc has the following struture
<table>
<tr>
<td>"The value of $y"</td>
</tr>
</table>
[/code]

The files are a bit more complicated than this (Gallery2 photo display software) but this is the basic structure.  I am struggling to get "The value of $y".  Any tips anyone... or clues on where I could go for suggestions???

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.