Jump to content

Nested variable scope


knowNothing

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]
Link to comment
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???
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.