Эта проблема довольно проста, я уверен, я просто не знаю ответа.
У меня есть класс, который расширяет другой класс.Когда я пытаюсь использовать parent :: method для использования функциональных возможностей родительского класса, я получаю «Вызов неопределенного метода 'parentClass' :: getid ()».
Что он делает, он вызывает имя методабыть в нижнем регистре.из приведенного выше примера parent :: getId () принудительно переходит к parent :: getid ();
Я не знаю, почему это так?Есть мысли?
Пример кода
Class myClass extends OtherClass {
public function getProductList() {
//does other stuff
return parent::getId();
}
}
попытался запустить parent :: getid () вместо parent :: getId ().getId () - это просто метод получения родительского класса, который является классом модели базы данных.
Также работает локально, это произошло только после моего бета-тестирования.*
parent::getId()
вызывает метод __call
/**
* @method __call
* @public
* @brief Facilitates the magic getters and setters.
* @description
* Allows for the use of getters and setters for accessing data. An exception will be thrown for
* any call that is not either already defined or is not a getter or setter for a member of the
* internal data array.
* @example
* class MyCodeModelUser extends TruDatabaseModel {
* ...
* protected $data = array(
* 'id' => null,
* 'name' => null
* );
* ...
* }
*
* ...
*
* $user->getId(); //gets the id
* $user->setId(2); //sets the id
* $user->setDateOfBirth('1/1/1980'); //throws an undefined method exception
*/
public function __call ($function, $arguments) {
$original = $function;
$function = strtolower(preg_replace('/(?<=[a-z])([A-Z])/', '_$1', $function));
$prefix = substr($function, 0, 4);
if ($prefix == 'get_' || $prefix == 'set_') {
$key = substr($function, 4);
if (array_key_exists($key, $this->data)) {
if ($prefix == 'get_') {
return $this->data[$key];
} else {
$this->data[$key] = $arguments[0];
return;
}
}
}
$this->tru->error->throwException(array(
'type' => 'database.model',
'dependency' => array(
'basic',
'database'
)
), 'Call to undefined method '.get_class($this).'::'.$original.'()');
}
Вот пример, который выдает ту же ошибку на PHP.net: http://www.php.net/manual/en/keyword.parent.php#91315