doujia9204 2016-09-02 19:37
浏览 78

如何查找现有类实例的命名空间

In this example, the platform used is Magento, but I believe this is a generic question related to Object Oriented Programming.

When a page or API URL is called, the first class to be instantiated will then instantiate other classes, and so forth. I need to change a setting in an instance of one class (there will only be one instance) from within another class.

For example, I am working in class Praxis_Rest_ProductsController::getAction() and want to do this:

(existing instance of Varien_Db_Adapter_Pdo_Mysql)->setDebug(true);

I know for sure that the connection class is Varien_Db_Adapter_Pdo_Mysql and that this is instantiated already, and only once.

How do I do this? Is this possible?

-- EDIT -- @Andrej Ludinovskov below posted a great solution if I know the object name, but in my case, I'm in a spot in the coding which has no relationship too it. In fact it might be 7-10 different classes in the stack downstream where that instantiated object is called; but I do know that class was instantiated and only once for that matter. In this case I'm trying to find $object when all I know is that it's an instance of Varien_Db_Adapter_Pdo_Mysql

  • 写回答

1条回答 默认 最新

  • dousi6192 2016-09-03 00:35
    关注

    Did you try this simple if or I miss something:

    if ($object instanceof Varien_Db_Adapter_Pdo_Mysql) {
        $object->setDebug(true);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图