In PHP can you extend a class to the same name?

Matt Lima picture Matt Lima · Jul 15, 2009 · Viewed 7.4k times · Source

I'm trying to find out weather I can do this or not. I have a class called Template. and I want to extend that classes functionality in another file, but I don't want to change the name.

Do I declare it as

class template extends template
{
   // code here
   function foo()
   {

   }
}

or do I just declare it like this?

class template
{
   // write function
   function foo()
   {

   }
}

Answer

Salman von Abbas picture Salman von Abbas · Jun 21, 2012

Only if the parent class is in another namespace.

use SomeNamespace\Template as BaseTemplate;

class Template extends BaseTemplate 
{
     //...
}