Jump to content

Archived

This topic is now archived and is closed to further replies.

johnnyk

require

Recommended Posts

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

[u]a.php[/u]
echo "hey";

[u]b.php[/u]
$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.

Share this post


Link to post
Share on other sites
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'
?>

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.