On May 12, 2006, at 1:55 PM, Stut wrote:
Edward Vermillion wrote:
But my thought is that since the include was from inside the
member function that the included function would be in the scope
of the member function, and not global. (?)
So if I have:
class foo {
function bar()
{
function baz(){}
}
}
Would baz() be out of class scope here? Or are includes
automatically global no matter where they are called? Or is it the
convoluted manner in which I'm getting to baz() that's causing this?
Scope is your issue here. Functions and classes defined in included
files are registered at the global level. Therefore within your
include file you do not have a $this because your function is
actually defined outside the class.
Thanks! I didn't know that, and it's a good piece of info to have.
The example you give above I'm not so sure about. I believe baz()
wouldn't have a $this variable, but stick some code in it to check.
Hopefully I'll never have to do anything that ridiculous (the
example), at least it seems so now. Although I am doing sort of the
same thing. Hopefully this is just an intermediate step (including
functions with an include() in a class method) to the proper solution
for my problem (it just seems wrong but I need something that will
work for now).
Like I said, it wasn't a big surprise that I had to pass in a
reference to the foo class, but it did make me wonder why.
Thanks for all the help!
Ed
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php