开发者

Parse error: parse error, expecting `T_FUNCTION' in my MVC framework [closed]

This question is unlikely to help any future vis开发者_StackOverflow社区itors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜