big issue with include_once !

mailling@bigfoot.com mailling@bigfoot.com
Thu, 19 Jul 2001 19:13:14 -0500


I am using php 4.0.6, so this issue may be recent.
Let's say I do that
	$a=include_once 'HTML/menu.php';
	$b=include_once 'HTML/menu.php';

Then $a=true but $b=null/false

That means that every code in the lib that has a method factory is not 
working rigth
In fact, we have that:

     function factory($driver, $params)
     {
         $driver = strtolower($driver);

         if (empty($driver) || (strcmp($driver, 'none') == 0)) {
             return new Group($params);
         }

         if (include_once dirname(__FILE__) . '/Group/' . $driver . '.php') {
             $class = 'Group_' . $driver;
             return new $class($params);
         } else {
             return false;
         }
     }

The problem is when we want to have different instances of an object (the 
parameters are different) but the driver is the same
So we will get a false for the include_once, so a false from the factory.
I think we have to replace everywhere
         if (include_once dirname(__FILE__) . '/Group/' . $driver . '.php') {
             $class = 'Group_' . $driver;
             return new $class($params);
         } else {
             return false;
         }

By:
	@include_once dirname(__FILE__) . '/Category/' . $driver . '.php';
             $class = 'Category_' . $driver;
	if (class_exists($class)) {

             return new $class($params);
         } else {
            return false;
         }

Also, I think it would be better to define the method like this:
     function &factory($driver, $params)

What do you think?