factory broken

From: Date: Wed, 01 Aug 2001 18:24:44 +0000
Subject: factory broken
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-1209@lists.php.net to get a copy of this message
I already sent this message to this list, but I got no answers/comments, so I decided to send it again. Either I am wrong, or every factories are broken. So comments would be appreciated. -- 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 that has a method factory is not working rigth Indeed, we have that: function factory ($log_type, $log_name = '', $ident = '', $conf = array()) { $log_type = strtolower($log_type); $classfile = 'Log/' . $log_type . '.php'; if (@include_once $classfile) { $class = 'Log_' . $log_type; return new $class($log_name, $ident, $conf); } else { return false; ... The problem is that the first factory will work fine, but the other will fail: (return false, instead of the new instance) 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 $classfile) { $class = 'Log_' . $log_type; ... By: @include_once $classfile; $class = 'Log_' . $log_type; if (class_exists($class)) { ... It migth be good also to add a constant such as PEAR_DIRECTORY to include the file, because some ISP may not let you change the php.ini or work wirh .htaccess Also, I think it would be better to define the method like this: function &factory($driver, $params) What do you think?

« previous php.pear.dev (#1209) next »