Jump to content


Photo

require


  • Please log in to reply
3 replies to this topic

#1 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 26 July 2006 - 02:01 AM

Is it possible to set a require to a variable?
Meaning:

a.php
echo "hey";

b.php
$a = require('a.php');
echo eval($a);

The problem I'm having is that b.php will echo "hey" even if I don't include the second line. When I do include the second line, it says:
Parse error: syntax error, unexpected $end eval()'d code on line 1

I want to set the evaluated a.php to a variable, and then change the value of the variable. So I'm altering what was already included. Make sense? I hope so.
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#2 High_-_Tek

High_-_Tek
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 26 July 2006 - 02:05 AM

Anything you include or require with <?php ?> tags is executed as PHP at run-time.

No you cannot assign a require call to a var but any var declared in the required file WILL become available to the file that included it.

For example this will work:

a.php
<?php
$a = 'lol';
?>

including file
<?php
include('a.php');
echo $a; // Produces 'lol'
?>

#3 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 26 July 2006 - 02:21 AM

Can I use str_replace on something that is required?
How about if I use fopen or something like that and set that to a variable?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#4 High_-_Tek

High_-_Tek
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 26 July 2006 - 02:25 AM

Only files included or required will be parsed as PHP, not fopen or file_get_contents and as I said before, you cannot perform any operation on the include statement, but you can do whatever the hell you want with the stuff that is returned from the included file




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users