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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.