假设我有一个类:
class Person
{
public function doSeomthing()
{
// ...
}
}
我想使用我自己的命名空间扩展这个类以添加额外的功能。使用相同的类名是好还是坏?例如:
命名空间自定义;
class Person extends \Person
{
public function doSomethingElse()
{
// ...
}
}
我对 PSR 标准对此有何看法特别感兴趣。
最佳答案
使用相同的类名,或 Name collisions
是命名空间专门用来解决的问题之一。http://www.php.net/manual/en/language.namespaces.rationale.php
In the PHP world, namespaces are designed to solve two problems that authors
of libraries and applications encounter when creating re-usable code elements
such as classes or functions:
1.Name collisions between code you create, and internal PHP
classes/functions/constants or third-party classes/functions/constants.
2. Ability to alias (or shorten) Extra_Long_Names designed to alleviate
the first problem, improving readability of source code.
关于php - 在 PHP 中使用命名空间扩展类时,我应该为类使用相同的名称吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17371638/