Re: function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



But the OP says "function is defined inside a different function".  Your 
theories to a solution don't fit that problem.
"tamouse mailing lists" <tamouse.lists@xxxxxxxxx> wrote in message 
news:CAHUC_t-416_-LPcn3mO8QqXWrh4pNq5fMWOuhWpDk+HmKGHh_A@xxxxxxxxxxxxxx...
On Thu, May 3, 2012 at 9:12 PM, Ron Piggott
<ron.piggott@xxxxxxxxxxxxxxxxxx> wrote:

Where is name_of_a_different_function defined? If it is somewhere in
the same file as name, that shouldn't be a problem, provided it is
defined in the same namespace/scope as name. If it is defined in a
different file, you need to include that file before you make the echo
statement.

For example:

function func1 ($flag1, $flag2) {

   # blah blah

   echo func2($flag1, $flag2);
}

function func2 ($flag1, $flag2) {

   #blah blah

   return "some string value";
}

in the same file should be just fine. It doesn't really matter what
order func1 and func2 are declared in.

However, if func2 is defined in some_other_file.php, you need to
include it in this_file.php (where func1 is defined) first:

this_file.php:
include('some_other_file.php');

function func1 ($flag1, $flag2) {

   #blah blah

   echo func2 ($flag1, $flag2);
}


some_other_file.php:
function func2 ($flag1, $flag2) {

   #blah blah

   return "some string value";
}

If func2 is a method for an object/class, you'll have to access it
that way in func1:

this_file.php:
include('MyClass.php');
function func1 ($flag1, $flag2) {

   # blah blah, instantiate object?
   $myobj = new MyClass();

   echo $myobj->func2 ($flag1, $flag2);
}

MyClass.php:
class MyClass
{
   function func2 ($flag1, $flag2) {

      #blah blah
      return "some string value";
   }
}

But the OP says "function is defined inside a different function".  Your 
theories to a solution don't fit that problem.

(Sorry you all had to read thru so much stuff just to get to my one-line 
response.) 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux