Jump to content

require


johnnyk

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.
Link to comment
https://forums.phpfreaks.com/topic/15645-require/
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'
?>
Link to comment
https://forums.phpfreaks.com/topic/15645-require/#findComment-63776
Share on other sites

Archived

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

×
×
  • Create New...

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.