Re: Silly question - include vs. eval

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

 



On Wed, 2009-03-11 at 14:03 +0100, Sándor Tamás (HostWare Kft.) wrote:
> Yes, Rob is right. My original question is about the difference between the 
> processing of a file-based site with include() OR eval(). In that case, if I 
> understood it correctly, the results are the same.
> 
> But! If the included pages contain functions, classes, etc. With eval(), can 
> I use them? With include(), I know I should be able to use them. But in some 
> mysterious cases I don't have access to a function. If I cut out from the 
> included file, and put in on the file which includes that, just before (or 
> after) the includ(), I don't have any problem with it.
> 
> The next step, that if I include a file in a function, can I use the 
> functions wrote in the included file?
> As I know, include just makes a copy-paste, so if I use it IN a function, 
> then all function will be in function scope, am I right?

You should be able to use any functions you declare in the external
source from within the including context... but only after the include.
This is true whether you include or eval the content.

It's interesting your mention a mysterious case... I remember a couple
of years ago an include issue where the functions were not available as
they should have been... I resolved it by doing an eval on the contents
of the file instead. I think it was probably some bug in PHP and it
eventually resolved itself and it had worked before an upgrade. I never
bothered with a bug report though because I couldn't distill it down to
a simple use case.

What version are you using?

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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