在 class 上访问祖父母 class 在 magento 中从兄弟姐妹覆盖

access grandparent class on class overwrites in magento, from a sibling

需要覆盖customer_resourceclass。我为资源重写添加了必需的 config.xml 选项,但是当覆盖 class 方法从自身调用 parent class 方法时,它实际上调用了我从中调用的 parent 方法扩展到 Mage_Customer_Model_Resource_Customer 的 parent:

  class My_Plugin_Model_Resource_Customer extends Mage_Customer_Model_Resource_Customer 
    {

    protected function _beforeSave(Varien_Object $customer){
        parent::_beforeSave($customer);
    ...
        }
    }

那么,在这种情况下如何正确调用parent方法呢? php 中可能存在某种双重向下转换?

最简单的解决方案,尤其是在这种情况下,是调用:

Mage_Eav_Model_Entity_Abstract::_beforeSave($customer);

因为 Mage_Customer_Model_Resource_Customer 所需的 parent 是 Mage_Eav_Model_Entity_Abstract 它将调用 grandparent.

另外还有ReflectionMethod->invoke()

的方法

更多信息在这里:How to call grandparent method without getting E_STRICT error?