Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/taoso/php-ns-quirk
PHP 名称空间的奇怪行为
https://github.com/taoso/php-ns-quirk
Last synced: about 2 months ago
JSON representation
PHP 名称空间的奇怪行为
- Host: GitHub
- URL: https://github.com/taoso/php-ns-quirk
- Owner: taoso
- License: mit
- Created: 2015-07-16T16:48:47.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-07-25T15:45:15.000Z (over 9 years ago)
- Last Synced: 2024-04-14T19:12:03.790Z (9 months ago)
- Language: PHP
- Size: 141 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP namespace quirk
Let's define three class, `Lv\Foo`, `Lv\Common\Foo` and `Lv\Bar` in `Foo.php`, `CommonFoo.php` and `Bar.php`.
The `Lv\Bar` extends the `Lv\Common\Foo` by using `use Lv\Common\Foo` and extends `Lv\Common\Foo`'s alias `Foo`.
And then, in `app.php`, if we make an instance of `Lv\Foo`, and then try to make an instance of `Lv\Bar`, the bellow error will be reported,
```
PHP Fatal error: Cannot use Lv\Common\Foo as Foo because the name is already in use in ...
```The expected result should be that the `Lv\Common\Foo`'s *alias* `Foo`, which is in the script `CommonFoo.php` with the `Lv` namespace will not confilict the `Lv\Foo`.