TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   TalkPHP Developer Team (http://www.talkphp.com/talkphp-developer-team/)
-   -   Some questions (http://www.talkphp.com/talkphp-developer-team/3881-some-questions.html)

Ross 01-17-2009 10:55 AM

Some questions
 
Hi all, glad this project finally got started!

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 :)

Thanks,

Salathe 01-17-2009 11:13 AM

VI might correct me, but as far as I'm aware we're using the period separator: class.myclass.php That said, at this early stage things are still in a state of flux so may change.

Ross 01-17-2009 11:44 AM

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?

PHP Code:

/* 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($namefalse) || !interface_exists($namefalse))
    {
        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.

Salathe 01-17-2009 12:05 PM

Quote:

Originally Posted by Ross (Post 21301)
are we planning to take advantage of PHP5's class/interface autoloading?

I do hope so.

Quote:

Originally Posted by Ross (Post 21301)
What is the minimum version of PHP we are supporting anyway (at least 5.1 I'd have thought).

At least. Since this is a downloadable app, I don't know how far back VI wants to cater for.

Quote:

Originally Posted by Ross (Post 21301)
I'm actually thinking a better method could be to stip out the class/interface part of the filename altogether now.

That would be my choice.

Village Idiot 01-17-2009 03:24 PM

I understand replacing the periods, that makes sense, but why strip out the layer that we put the class files in?

Ross 01-17-2009 03:32 PM

Quote:

Originally Posted by Village Idiot (Post 21306)
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.

Village Idiot 01-17-2009 07:49 PM

I thought you meant something else. Sounds like a good idea.

Ross 01-17-2009 10:01 PM

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

Village Idiot 01-17-2009 10:22 PM

I don't see why not, the cleaner the better.

infonama 06-03-2010 04:37 AM

Agree with Village Idiot. the cleaner the better.


All times are GMT. The time now is 12:26 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0