php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #78659 导入全局类
Submitted: 2019-10-10 08:09 UTC Modified: 2019-10-10 19:29 UTC
From: 513335394 at qq dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.3.10 OS: liunx
Private report: No CVE-ID: None
 [2019-10-10 08:09 UTC] 513335394 at qq dot com
Description:
------------
---
From manual page: https://php.net/language.namespaces.importing
---

$a = new ArrayObject(array(1)); // 实例化 ArrayObject 对象
// 如果不使用 "use \ArrayObject" ,则实例化一个 foo\ArrayObject 对象


Test script:
---------------
use \ArrayObject 
use ArrayObject
都能引入全局类 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-10-10 08:16 UTC] 513335394 at qq dot com
use ArrayObject;
和
use \ArrayObject;
应该使用哪一个?
 [2019-10-10 19:29 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: PHP Language Specification +Package: Scripting Engine problem
 [2019-10-10 19:29 UTC] requinix@php.net
I think I can get this...

两者都被允许. "use ArrayObject" == "use \ArrayObject"
"use ArrayObject" 或 "new \ArrayObject" 是标准做法.

https://www.php.net/manual/zh/language.namespaces.php
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Apr 21 21:01:24 2021 UTC