Php 父::方法,方法被强制为小写,导致找不到方法

Php 父::方法,方法被强制为小写,导致找不到方法,php,class,methods,parent,lowercase,Php,Class,Methods,Parent,Lowercase,这个问题很简单,我肯定,我就是不知道答案 我有一个类扩展了另一个类。当我尝试parent::method使用父类中的功能时,我得到“调用未定义的方法‘parentClass’::getid()” 它所做的是强制方法名小写。从上面的示例中,parent::getId()被强制为parent::getId() 我不知道这是为什么?有什么想法吗 代码示例 Class myClass extends OtherClass { public function getProductList() {

这个问题很简单,我肯定,我就是不知道答案

我有一个类扩展了另一个类。当我尝试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()只是父类(数据库模型类)上的一个getter

也在本地工作,只是在我推出测试版之后才发生了这种情况

更新

parent::getId()
调用
\u调用
方法

/**
 * @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.'()');
}
/**
*@method\u调用
*@公众
*@brief有助于神奇的接球手和二传手。
*@说明
*允许使用getter和setter访问数据。将为“”引发异常
*任何尚未定义的调用,或者不是的成员的getter或setter
*内部数据数组。
*@example
*类扩展TruDatabaseModel{
*  ...
*受保护的$data=array(
*'id'=>null,
*'name'=>null
*  );
*  ...
* }
* 
* ...
* 
*$user->getId()//获取id
*$user->setId(2)//设置id
*$user->setDateOfBirth('1/1/1980')//引发未定义的方法异常
*/
公共函数调用($function,$arguments){
$original=$function;

$function=strtolower(preg_replace('/(?我试图在PHP5.3.3中的编辑中验证链接到的代码,但是我得到了

A getTest
B getTest
与评论输出的

A getTest
B gettest
所以我能想到的唯一一件事是,您使用的是其他版本的PHP,而您遇到的行为是一个bug(倒退或不倒退)

编辑:找到了它,该问题已在:

如果在子类中调用了
(注意:这不是一个静态调用),并且
在父类中不存在,则将以小写形式为父类的
\u call()
magic方法提供方法名(
$name
参数)

  • 修复了错误(_call()通过parent::operator访问时提供了不正确的方法名)。(Felipe)

我试图在PHP5.3.3中的编辑中验证链接到的代码,但是我得到了

A getTest
B getTest
与评论输出的

A getTest
B gettest
所以我能想到的唯一一件事是,您使用的是其他版本的PHP,而您遇到的行为是一个bug(倒退或不倒退)

编辑:找到了它,该问题已在:

如果在子类中调用了
(注意:这不是一个静态调用),并且
在父类中不存在,则将以小写形式为父类的
\u call()
magic方法提供方法名(
$name
参数)

  • 修复了错误(_call()通过parent::operator访问时提供了不正确的方法名)。(Felipe)

您可以发布这两个类的实际代码吗?我以前从未见过这种行为,如果不实际编写
parent::getid(),我也无法在PHP5.3上验证它
小写。@Webnet:你从哪里得到的代码?你怎么知道它是OP的代码?因为他是我的同事^ ^顺便说一句,Murilo Vasconcelos在他现在删除的答案中说的是正确的:你没有调用正确的getter。你能发布这两个类的实际代码吗?我以前从未见过这种行为,也无法在PHP上验证它5.3没有用小写字母写
parent::getid()
。@Webnet:你从哪里得到的代码?你怎么知道它是OP的代码?因为他是我的同事^ ^ ^ ^顺便说一句,Murilo Vasconcelos在他现在删除的答案中说的是正确的:你没有调用正确的getter.PHP版本:LIVE:5.2.6 LOCAL:5.3.2(live是我遇到问题的地方,本地的很好。)@Chris Flynn:看我的编辑,很明显这个错误出现在5.2.6中。@Webnet,@Chris:没问题:)PHP版本:live:5.2.6本地的:5.3.2(live是我遇到问题的地方,本地的很好).@Chris Flynn:看我的编辑,很明显这个bug出现在5.2.6中。@Webnet,@Chris:没问题:)