PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Rooster242
Forum Newbie
Posts: 18 Joined: Thu Aug 31, 2006 6:23 pm
Post
by Rooster242 » Fri Sep 01, 2006 1:05 pm
first_file.php:
second_file.php:
Code: Select all
$var = "blah";
$text = file_get_contents( "first_file.php" );
eval( $text );
ouput:
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Sep 01, 2006 1:21 pm
I cannot reproduce this behaviour.
PHP 5.1.5 (cli) (built: Aug 15 2006 23:54:56) wrote: This is var: blah
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Fri Sep 01, 2006 1:24 pm
what version of php are you running?
Rooster242
Forum Newbie
Posts: 18 Joined: Thu Aug 31, 2006 6:23 pm
Post
by Rooster242 » Fri Sep 01, 2006 1:34 pm
The Ninja Space Goat wrote: what version of php are you running?
5.1.4
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Sep 01, 2006 2:38 pm
Is there more code around the snippet you've posted?
Rooster242
Forum Newbie
Posts: 18 Joined: Thu Aug 31, 2006 6:23 pm
Post
by Rooster242 » Fri Sep 01, 2006 3:50 pm
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Sep 01, 2006 5:38 pm
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.
Rooster242
Forum Newbie
Posts: 18 Joined: Thu Aug 31, 2006 6:23 pm
Post
by Rooster242 » Fri Sep 01, 2006 6:05 pm
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
Rooster242
Forum Newbie
Posts: 18 Joined: Thu Aug 31, 2006 6:23 pm
Post
by Rooster242 » Mon Sep 11, 2006 1:06 pm
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...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Sep 11, 2006 3:16 pm
Sounds like a redesign is in order.
bokehman
Forum Regular
Posts: 509 Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)
Post
by bokehman » Mon Sep 11, 2006 3:20 pm
Try using a proper file path rather than an http wrapper.