【问题标题】:`new` and `use` keyword paths`new` 和 `use` 关键字路径
【发布时间】:2011-10-28 10:20:55
【问题描述】:

我在使用 php 5.2 的主机公司,我使用的一些库是用 5.3 编写的,并且代码之间存在某些不兼容性。

首先有什么替代方法:

use \folder1\folder2\class_file;

其次是什么:

$sample = new \folder1\folder2\class_file($arg1, arg2);

提前致谢。

【问题讨论】:

  • "新 \folder1\folder2\class_file($arg1, arg2);"是“use \folder1\folder2\class_file;”的替代品,因此避免使用“use”。

标签: php namespaces new-operator slash php-5.2


【解决方案1】:

命名空间向后兼容 PHP

你将不得不:

  • 删除所有 namespaceuse 语句的情况
  • 将您的课程从 class_file 重命名为 folder1_folder2_class_file(或类似名称)
  • 使用$sample = new folder1_folder2_class_file($arg1, $arg2);创建实例

【讨论】:

    【解决方案2】:

    我会说这取决于 PHP 5.3 代码的数量以及您的项目是否对您来说每月价值超过 5 美元。

    我的主要建议是:更换您的托管服务提供商。

    如果他们不提供 PHP 5.3,即 2009 年 6 月 30 日发布的 PHP 版本(即两年!),您最好不要浪费时间尝试让您的项目跑过去。

    5.3 已经足够成熟,可以在生产中使用,5.2 已经到了生命周期的尽头(end of support for php 5.2 branch)。

    不要因为某些托管公司而浪费时间创建“旧”应用程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 1970-01-01
      • 2015-10-12
      • 1970-01-01
      • 1970-01-01
      • 2016-04-05
      • 2012-04-05
      相关资源
      最近更新 更多