帮助理解 PHP5 错误
简而言之......问题是......“说什么?”扩展...“我没有收到错误”
严格标准:非静态方法 Pyro\Template::preLoad() 不应静态调用,假设 $this 来自 /opt/lampp/htdocs/dc/pyro/app/controllers/admin/courses 中不兼容的上下文。 php 第 14 行
public function actionIndex() {
$this->data->users = $this->DB->query("SELECT id, name, description FROM :@courses")->getAll();
$this->data->title = 'Courses';
$this->data->content_area = \Pyro\Template::preLoad('admin/courses/index', $this->data); // Line 14
}
模板...不完整...
<?php
namespace Pyro;
class Template {
// Stores default master template
public static $defaultTemplate = 'template.php';
public function preLoad($template, $page) {
ob_start();
include( VIEWS . "{$template}.php");
$buffer = ob_get_contents();
@ob_end_clean();
return $buffer;
}
public function load($page) {
include( VIEWS . self::$defaultTemplate);
}
}
为什么会出现这个错误?干杯
In short.. question is... "Say what?" To expand... "I don't get the error"
Strict Standards: Non-static method Pyro\Template::preLoad() should not be called statically, assuming $this from incompatible context in /opt/lampp/htdocs/dc/pyro/app/controllers/admin/courses.php on line 14
public function actionIndex() {
$this->data->users = $this->DB->query("SELECT id, name, description FROM :@courses")->getAll();
$this->data->title = 'Courses';
$this->data->content_area = \Pyro\Template::preLoad('admin/courses/index', $this->data); // Line 14
}
Template... its incomplete...
<?php
namespace Pyro;
class Template {
// Stores default master template
public static $defaultTemplate = 'template.php';
public function preLoad($template, $page) {
ob_start();
include( VIEWS . "{$template}.php");
$buffer = ob_get_contents();
@ob_end_clean();
return $buffer;
}
public function load($page) {
include( VIEWS . self::$defaultTemplate);
}
}
Why does this error appear? Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
那么 preLoad 函数不是静态的。这意味着只有 Template 类的对象可以使用此方法。静态方法独立于类的任何对象而存在。
Template::preLoad 是静态调用:您没有创建 Template 对象,然后调用 preLoad 方法。所以基本上,你有两个解决方案:
Well the preLoad function is not static. Which means only an object of the class Template can use this method. A static method exists indepedently of any object of the class.
Template::preLoad is a static call : you didn't create a Template object, then call the preLoad method. So basically, you've got two solutions :
preLoad
函数应该是静态的preLoad
function should be staticpreLoad 函数不是静态的。 ti 应该看起来像这样:
preLoad function isn't static. ti should look like this:
正如大家所说,您将函数作为静态方法调用:
Template::preLoad(xxx)
::
在 PHP 中表示静态。函数通常被称为静态::
或对象->
调用。函数定义是其中之一:
public static function preLoad($template, $page)
调用方式如下:
Template::preLoad('admin/courses/index', $this-> ;data);
OR
public function preLoad($template, $page)
调用方式类似于
Template->preLoad('admin/courses/index ', $this->data);
作为参考,静态函数无需实例化对象即可调用。如果您的函数不需要对象来运行,您可以将其设为静态。基本上,这意味着您无法在静态方法中引用
$this
。它将使用给定的输入运行,而无需构造对象。Like everyone said, the you called the function with as a static method:
Template::preLoad(xxx)
The
::
means static in PHP. Functions are typically called as static::
or object->
calls.The function definition is one or the other:
public static function preLoad($template, $page)
Called like:
Template::preLoad('admin/courses/index', $this->data);
OR
public function preLoad($template, $page)
Called like
Template->preLoad('admin/courses/index', $this->data);
For reference, a static function is able to be called without instantiating an object. If your function doesn't need an object to run, you could make it static. Basically, this means you can't reference
$this
in a static method. It will run with the given inputs without having to construct the object.