dongpin4611 2011-09-06 21:33
浏览 28
已采纳

PHP 5.3.2:实例化对象的不推荐使用的方法?

Getting a white screen of death, so decided to remote debug an application that I suspect is instantiating an object using a now unsupported method:

$type['content_object'] = new $type['handler_class']();

Is this still legitimate?

  • 写回答

1条回答 默认 最新

  • douyue4334 2011-09-06 21:36
    关注

    Assuming $type['handler_class'] is a string containing the name of a class, then it's fine, according to the manual:

    If a string containing the name of a class is used with new, a new instance of that class will be created.

    <?php
        $instance = new SimpleClass();
    
        // This can also be done with a variable:
        $className = 'Foo';
        $instance = new $className(); // Foo()
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题