PHP 5.3.2:实例化对象的方法已弃用? [英] PHP 5.3.2: Deprecated method of instantiating an object?

查看:71
本文介绍了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']();

这仍然合法吗?

推荐答案

假设 $ type ['handler_class'] 是包含以下名称的字符串一个类,那么根据手册

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


如果将包含类名的字符串与new一起使用,则会创建该类的新实例。

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()
?>


这篇关于PHP 5.3.2:实例化对象的方法已弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆