问题
Afternoon guys!
For some reason Complex (Curly) Syntax in my PHP code doesn't interpreter as variable
function view($name, $data = [])
{
require __DIR__ . '/../app/views/{$name}.view.php';
}
Here is the code I am calling view('index'); the problem is I get this error:
Warning: require(./core/../app/views/{$name}.view.php): failed to open stream
By the way my PHP version before anyone asks is 7.0.13
Thanks for your help!
回答1:
Your string has to be placed in double quotes (") instead of single quotes ('). Otherwise variables won't be replaced.
Look here: https://secure.php.net/manual/en/language.types.string.php#language.types.string.syntax.single
Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.
来源:https://stackoverflow.com/questions/41523946/complex-curly-syntax-php