Parse error: parse error, expecting `T_FUNCTION' in my MVC framework [closed]
I'm following the Create your First Tiny MVC Boilerplate with PHP tutorial, and as far as I can tell--my code is identical to Jeff's code... yet I'm receiving this error:
Parse error: parse error, expecting `T_FUNCTION' in D:\wamp\www\MVC_test\application\load.php on line 8
load.php
<?php
class Load {
function view( $file_name, $data = NULL )
{
if( is_array($data) ) { extract($data); }
}
include 'views/' . $file_name;
}
?>
I've tried a few different things, but I don't understand what is wrong with line 8.
This line
include 'views/' . $file_name;
is inside a class but outside a method, which is not possible in PHP.
$file_name is local variable inside the function can not be used outside it
it's not allowed to write plain code outside the method in the class body
//replace
function view( $file_name, $data = NULL )
{
if( is_array($data) ) { extract($data); }
}
include 'views/' . $file_name;
//with
function view( $file_name, $data = NULL )
{
if( is_array($data) ) { extract($data); }
include 'views/' . $file_name;
}
You can't include in a class definition with an expression
<?php
class Load {
function view( $file_name, $data = NULL )
{
include 'view/'.$file_name;
if( is_array($data) ) { extract($data); }
}
}
?>
This line should be,
include ('views/' . $file_name);
php include
精彩评论