RE: [PHP] Make class only declare once!

From: Date: Mon, 08 Jan 2001 03:38:05 +0000
Subject: RE: [PHP] Make class only declare once!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-33168@lists.php.net to get a copy of this message
If you use PHP 4.0, using include_once() instead of include() might help you. Also, the following code might help: if (!class_exists(string class_name)) { class Foo_BR extends Foo_Bar{ var $Foo= "bar"; var $Bar = "Foo"; } } I haven't try it, but in case PHP doesn't allow to put class definitions inside an if clause, use the following code instead: if (!class_exists(string class_name)) { eval( " class Foo_BR extends Foo_Bar{ var $Foo= "bar"; var $Bar = "Foo"; } "); } Seems an ungly hack, but it's all I can think of right now. Cheers. -----Original Message----- From: Chris Doyle [mailto:gaur@planetveggie.com] Sent: Sunday, 07 January, 2001 9:12 PM To: dful@metahogar.com Cc: PHP users Subject: [PHP] Make class only declare once! Hi, Anyone know how I can make a class only declare itself once no-matter how many times I include the file? I need this to only run once... class Foo_BR extends Foo_Bar{ var $Foo= "bar"; var $Bar = "Foo"; }

« previous php.general (#33168) next »