我是OOP的新手,但不是PHP的新手.我正在尝试从另一个类中初始化一个类.
的index.php
<?
error_reporting(E_ALL);
require("classes/memcache.php");
require("classes/video_test.php");
$videos = new video;
?>
Run Code Online (Sandbox Code Playgroud)
video_test.php
<?php
class video {
private $mcache;
public function __construct() {
$this->mcache = new MCACHE();
}
public static function get_scene($scene_id) {
$info = $this->$mcache->get_item("mykey");
}
}
?>
Run Code Online (Sandbox Code Playgroud)
生成:PHP致命错误:在不在对象上下文中时使用$ this
当不在对象上下文中时使用$ this
你不能在声明为static的方法中使用$ this.只需删除static关键字并通过对象句柄使用您的方法:
$vid = new video()
$vid->get_scene();
Run Code Online (Sandbox Code Playgroud)