Re: function
| From: | Jim Giner | Date: | Sat, 05 May 2012 02:18:53 +0000 |
| Subject: | Re: function | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-317797@lists.php.net to get a copy of this message | ||
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@gmail.com> wrote in message
news:CAHUC_t-416_-LPcn3mO8QqXWrh4pNq5fMWOuhWpDk+HmKGHh_A@mail.gmail.com...
On Thu, May 3, 2012 at 9:12 PM, Ron Piggott
<ron.piggott@actsministries.org> 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.)