Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

class

extends

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()
   {

   }
}

like image 562
Matt Lima Avatar asked Jul 14 '09 23:07

Matt Lima


1 Answers

Only if the parent class is in another namespace.

use SomeNamespace\Template as BaseTemplate;

class Template extends BaseTemplate 
{
     //...
}
like image 88
Salman von Abbas Avatar answered Oct 04 '22 09:10

Salman von Abbas