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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 513335394 at qq dot com
New email:
PHP Version: OS:

 

 [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: Sun Apr 18 06:01:23 2021 UTC