函数oop导致标题失败


failure of title by function - oop

这就是我在学习了OOP之后,现在用OOP构建页面的方法。

这就是我想要h1的正确标题和前面的标题的方式

但我把它放在头版,我得到了错误:

在我的错误日志中:

〔20-Apr-2014 01:17:16欧洲/柏林〕PHP致命错误:使用$this当不在中的对象上下文中时/home/jesperbo/public_html/balabla.com/index.php,第17行

index.php

<?php
include("inc/incphp-f.php");
?>
<!--- more code her --->
    <title>
        <?php
            $this->indextitle;
        ?>
    </title>
<!--- More code her --->

我获得所有php文件和信息的地方是`incphp-f.php here&我的功能:

    if(IN_DEBUG_MODE){
    ini_set("display_startup_errors", "on");
    ini_set("display_errors", "on");
    ini_set("html_errors", "false");
    error_reporting(-1); // -1 viser alle slags fejl beskeder
    ini_set("ignore_repeated_errors", 0);
}
else{
    error_reporting(0);
}
class mebe
{
    public $indextitle = "Hello world";
//more php here after 
}

为什么它会犯它所描述的错误?

错误状态:

〔20-Apr-2014 01:17:16欧洲/柏林〕PHP致命错误:使用$this时不在中的对象上下文中/home/jesperbo/public_html/balabla.com/index.php,第17行

当不在类的范围内时,您正在尝试使用$this。这行不通。只能在类结构本身中使用$this。请在index.php:中尝试此操作

<?php
include("inc/incphp-f.php");
$mebe_class = new mebe();
?>
<!--- more code her --->
    <title>
        <?php
            $mebe_class->indextitle;
        ?>
    </title>
<!--- More code her --->

主要区别在于,我通过$mebe_class = new mebe();实例化类,然后使用它通过$mebe_class->indextitle; 调用indextitle