Home > Backend Development > PHP Tutorial > Interesting facts about namespaces

Interesting facts about namespaces

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-04 09:21:56
Original
1280 people have browsed it

I found an interesting question. Within a file without a namespace.

<code>use PDO; 或者 use \PDO;
$conn = new PDO(....);
会报出一个错误 Warning: The use statement with non-compound name 'PDO' has no effect......

然而下面几种做法不会报这个错误
use PDO as PDO;
use \PDO as PDO;
或者
直接 $conn = new PDO(....);
$conn = new \PDO(....);
都是不会报错的。
</code>
Copy after login
Copy after login

Then the question comes, why can’t you use PDO for files without namespace;

Updated on July 11, 2016 22:18:51 ----------
The above test is in the php7 environment.
It is possible to use PDO in 5.4 environment, but use PDO still doesn’t work

Reply content:

I found an interesting question. Within a file without a namespace.

<code>use PDO; 或者 use \PDO;
$conn = new PDO(....);
会报出一个错误 Warning: The use statement with non-compound name 'PDO' has no effect......

然而下面几种做法不会报这个错误
use PDO as PDO;
use \PDO as PDO;
或者
直接 $conn = new PDO(....);
$conn = new \PDO(....);
都是不会报错的。
</code>
Copy after login
Copy after login

Then the question comes, why can’t you use PDO for files without namespace;

Updated on July 11, 2016 22:18:51 ----------
The above test is in the php7 environment.
It is possible to use PDO in 5.4 environment, but use PDO still doesn’t work

http://stackoverflow.com/questions/9317022/troubleshooting-the-use-statement-with-non-compound-name-has-no-effect

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template