我有这样的一行代码,从名为场一类的名字叫buildField的方法
$field_dictionary[$key] = Field::buildField($key, $request);
在Field类,这里是我buildField方法
public function buildField($key, $request) {
$field_vocabulary = [];
$image = $_FILES[$key];
$image['tmp_name']['image'] = true;
// Calling this another method from same class
$field = $this->sanitizeFieldRows($image['tmp_name'], $request->post($key . '_name'), $request->post($key . '_description'));
$field_vocabulary['name'] = implode('|', $field->field_1);
$field_vocabulary['description'] = implode('|', $field->field_2);
$field_vocabulary['image'] = implode('|', $field->reference);
return $field_vocabulary;
}
在该代码中,有一个该行
$field = $this->sanitizeFieldRows($image['tmp_name'], $request->post($key . '_name'), $request->post($key . '_description'));
我打电话从SAM另一种方法e类。它做了一些我刚刚删除的功能,因为它太长了。
public function sanitizeFieldRows($reference, $field_1, $field_2 = null) {
// Some code etc.....
// Outputs an object
return (object) $output;
}
但事实是,我打电话$this->sanitizeFieldRows($par1,$par2,$par3)
但它提示一个错误说:
Using $this when not in object context in
但是,当我做Field::sanitizeFieldRows($par1,$par2,$par3)
它的工作原理,但这些方法是在同一个对象但它不是我打电话的静态方法。
有什么问题吗?
这是同样的问题:
Using $this when not in object context?
Using $this when not in object context
Using $this when not in object context
PHP using $this when not in object context
Fatal error: Using $this when not in object context
Fatal error: Using $this when not in object context explanation?
Using $this when not in object context php
你实例化你的类?如果处于静态模式,则可以使用'self :: sanitizeFieldRows($ par1,$ par2,$ par3)'。 –
^感谢这也@Vincent Decaux,今天学到了一些东西。 –