php - 使用命名空间但不用于默认类

标签 php namespaces

从昨天开始,我将在 php 中使用命名空间,但我在那里遇到了一个小问题:

namespace NamespaceName;

use StdClass;

$s = new StdClass;
$s->meow = "Hello World";

echo $s->meow;

有什么办法可以不包括“使用 StdClass”?

最佳答案

你只需要在你的声明中放一个退格,这样你就可以使用全局命名空间中的 StdClass :

 $s = new \StdClass;
        //^ See here

关于php - 使用命名空间但不用于默认类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29509024/

相关文章:

php - MySql Yii2 如何显示单元格值?

php - 如何在没有任何自定义表单类型类的情况下创建多个字段的集合?

javascript - 使用 jQuery 解析 xml 命名空间。需要帮助!

php - Codeception 生成的功能测试引发错误 'use statement with non-compound name'

php - 图表 : database data can't insert to the bar chart using php

php - mysql_affected_rows 不工作

c# - 在 asp.net + jquery 中实现自动注销 + 警告?

xml - XSLT 1.0 的命名空间输出导致问题

typescript - 如何从 Typescript 中包含多种类型的命名空间中获取联合类型?

c# - 带有命名空间但没有 xmlns 的 XML