johnnyk Posted July 26, 2006 Share Posted July 26, 2006 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 1I 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. Quote Link to comment https://forums.phpfreaks.com/topic/15645-require/ Share on other sites More sharing options...
High_-_Tek Posted July 26, 2006 Share Posted July 26, 2006 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<?phpinclude('a.php');echo $a; // Produces 'lol'?> Quote Link to comment https://forums.phpfreaks.com/topic/15645-require/#findComment-63776 Share on other sites More sharing options...
johnnyk Posted July 26, 2006 Author Share Posted July 26, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/15645-require/#findComment-63782 Share on other sites More sharing options...
High_-_Tek Posted July 26, 2006 Share Posted July 26, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/15645-require/#findComment-63785 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.