Jump to content


Photo

Nested variable scope


  • Please log in to reply
1 reply to this topic

#1 knowNothing

knowNothing
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 12 October 2006 - 05:48 PM

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?

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

?>


#2 dayo

dayo
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 October 2006 - 06:28 PM

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

<?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>

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???




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users