I'm about to start work on making the codebase a little cleaner but have a question:
How are we naming files?
Not entirely sure from the forums, but I'd like so suggest something like: class_classname.php & interface_intname.php. I've used the period separated version before but I think that using underscores is a better method. Periods are meant for separating the filename from the extension really.
I couldn't find any posts on this - let me know if I didn't look hard enough :)
That's fine. I've just thought of something though - are we planning to take advantage of PHP5's class/interface autoloading? What is the minimum version of PHP we are supporting anyway (at least 5.1 I'd have thought).
Anyway, I was writing an autoload function to use the class/interface.name.php - can you see what's wrong below?
/* snip: Phlox_Registry */
* Class/interface autoloader
* @param string $name Name of the class or interface
* @throws Exception if unable to load the class/interface
public static function autoload($name)
require_once APPLICATION_PATH . '/core/' . strtolower(str_replace('_', '.', $name)) . '.php';
if (!class_exists($name, false) || !interface_exists($name, false))
throw new Exception("Unable to load the class or interface '$name'.");
/* snip: Phlox_Registry */
$class = new ClassName(); // should be in /core/class.classname.php
$interface = new InterfaceName(); // should be in /core/interface.interfacename.php
If we keep 'class' or 'interface' in the name of the file we're going to have a hard job including them unless we make the classnames something like: class Class_ClassName and interface Interface_InterfaceName.
I'm actually thinking a better method could be to stip out the class/interface part of the filename altogether now.
I understand replacing the periods, that makes sense, but why strip out the layer that we put the class files in?
By layer I assume you mean the class. / interface. part of the filename?
My reasoning is that if we use an autoload (which makes things mcuh easier) there's no way to tell whether it's an interface or a class that needs to be loaded. Stripping out that identifier from the name makes things a little easier. Otherwise we'd have to include both class_name.php and interface_name.php (which isn't too good) and check which one wasn't included.
Thinking about it, the require in my method should be an include - otherwise it will just fatal the app before we even get to the exception.
Another thing, what do you think about prefixing classes with Phlox_?
I've started to do that on the Registry/Config classes (I suppose it stops clashes with other libraries) but I'm not a huge fan of it - I'd prefer Registry::getInstance to Phlox_Registry::getInstance. Not a huge issue, but something to get out of the way early on.
Also: If you're online get in the irc channel! No point me being on my own in here =P