1

假设我有一堂课:

class Person
{
  public function doSeomthing()
  {
    // ...
  }
}

我想扩展这个类来添加额外的功能,使用我自己的命名空间。使用相同的类名是好主意还是坏主意?例如:

命名空间自定义;

class Person extends \Person
{
  public function doSomethingElse()
  {
    // ...
  }
}

我对 PSR 标准对此的感受特别感兴趣。

4

1 回答 1

2

使用相同的类名,或者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.
于 2013-06-28T19:24:10.720 回答