This problem is pretty simple, im sure, i just dont know the answer.
I have a class that extends another class. When I try parent::method to use the functionality from the parent class, I get "Call to undefined method 'parentClass'::getid()".
What its doing is, it is forcing the method name to be lowercased. from the example above, parent::getId() is being forced to parent::getid();
I do not know why this is? Any thoughts?
Code example
Class myClass extends OtherClass {
public function getProductList() {
//does other stuff
return parent::getId();
}
}
tried to run parent::getid() instead of parent::getId(). getId() is just a getter on the parent class which is a database model class.
Also worked locally, its only after my beta push that this happend.
update
parent::getId()
invokes the __call
method
/**
* @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.'()');
}
Here's an example that throws the same error on PHP.net: http://www.php.net/manual/en/keyword.parent.php#91315
I tried to verify the code in that comment linked to in the edit in PHP 5.3.3 but I get
A getTest
B getTest
As opposed to the comment's output of
A getTest
B gettest
So the only thing I can think of is that you're using some other version of PHP and you're encountering that behavior as a bug (regressed or not).
EDIT: found it, indeed a bug that was fixed in PHP 5.2.10:
If
parent::<method-name>
(NOTE: this is *not* a static invocation) is called in a child class, and<method-name>
does not exist in the parent, the parent's__call()
magic method is provided the method name (the$name
argument) in lower case.
- Fixed bug #47801 (__call() accessed via parent:: operator is provided incorrect method name). (Felipe)