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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC