I am experimenting with OOP yet, I am very new to it so,
I have created a module for joomla 2.5.x and inside it's main php file I require_once
a file with a class like this:
require_once(JPATH_SITE.'/modules/'.$module_dir.'/libs/classes.php');
classes.php contains this:
class experiment
{
function clean($input)
{
return filter_var($input, FILTER_SANITIZE_STRING);
}
}
$my = new experiment;
Then in the module php file I use it like:
$name = $my->clean($params->get('name'));
Until this point it all behaves normal. But that only when the module appears only once on the same page. If I duplicate the module and use it twice on the same page I get the error Undefined variable my
. If I change the require_once
to require
, I get the error Cannot redeclare class experiment
. Weird.
I have also tried if (!class_exists(..
or if(!isset($my)) { .. }
but I knew it was not going to work.
I will appreciate any kind of help, cheers.