Page 1 of 1
eval limitation or scope issue?
Posted: Fri Sep 01, 2006 1:05 pm
by Rooster242
first_file.php:
second_file.php:
Code: Select all
$var = "blah";
$text = file_get_contents( "first_file.php" );
eval( $text );
ouput:
Posted: Fri Sep 01, 2006 1:21 pm
by volka
I cannot reproduce this behaviour.
PHP 5.1.5 (cli) (built: Aug 15 2006 23:54:56) wrote:This is var: blah
Posted: Fri Sep 01, 2006 1:24 pm
by Luke
what version of php are you running?
Posted: Fri Sep 01, 2006 1:34 pm
by Rooster242
The Ninja Space Goat wrote:what version of php are you running?
5.1.4
Posted: Fri Sep 01, 2006 2:38 pm
by volka
Is there more code around the snippet you've posted?
Posted: Fri Sep 01, 2006 3:50 pm
by Rooster242
i found the problem. i was actually using
Code: Select all
$text = file_get_contents( "http://localhost/firstfile.php" );
so my web server is evaluating the php in firstfile.php before the eval() call and before $var is defined.
Posted: Fri Sep 01, 2006 5:38 pm
by feyd
If you don't know exactly what you're doing, steer clear of using eval(). In many hands, both inexperienced and experienced, it is a dangerous function that can get you into a lot of problems.
Posted: Fri Sep 01, 2006 6:05 pm
by Rooster242
yeah, i'm starting to realize that. but it seems to be the only solution for what i'm trying to do unless i want to do some wierd token replacement and pass a uri to file_get_contents() instead of a local path.
see
viewtopic.php?t=54763
Posted: Fri Sep 01, 2006 9:25 pm
by Ollie Saunders
Why can't you use require_once?
Posted: Mon Sep 11, 2006 1:06 pm
by Rooster242
ole wrote:Why can't you use require_once?
because i'm doing other things with the file before i let the web server have it, like replacing strings for different languages etc...
Posted: Mon Sep 11, 2006 3:16 pm
by feyd
Sounds like a redesign is in order.
Posted: Mon Sep 11, 2006 3:20 pm
by bokehman
Try using a proper file path rather than an http wrapper.