Take the 2-minute tour ×

I am having a problem with detecting if an interface class is already declared

Error reported is:

Fatal error: Cannot redeclare class iSerializable in /public_html/application/AppCode/iSerializable.interface.php on line 3

line1: //nothing here
line2:  require_once($filename);    
line3:  interface iSerializable
            public function writeXML(DomDocument $doc, DomElement $element);

If this was a normal class, then i would have used this example function given below

if(class_exists('iSerializable') != true)
   //put class iSerializable here

but here, this class is an Interface, how can i check if this interface is already declared?

Can any one kindly suggest me a proper way or solution to this problem?

share|improve this question
Ehem.. interface_exists()? –  Niko Jun 27 '12 at 18:33
You're probably stuck in an include loop. iSerializable includes a file that includes iSerializable again. This shouldn't happen. If your interface doesn't extend another interface, why would you need a require statement? –  netcoder Jun 27 '12 at 18:47
Thanks a lot!, your information is correct and very helpful :) –  Me 4U Jun 27 '12 at 18:49

2 Answers 2

up vote 2 down vote accepted

You can use interface_exists()

share|improve this answer
interface_exists() seems to be working, thanks! –  Me 4U Jun 27 '12 at 18:47

interface iSerializable is an interface, not a class. You are trying to validate if a class exists, which technically it doesn't. A class does not denote an interface.

Look into interface_exists()

share|improve this answer
Thank you - Very useful information! –  Me 4U Jun 27 '12 at 18:47

Your Answer


