TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-17-2009, 10:55 AM   #1 (permalink)
The Contributor
 
Ross's Avatar
 
Join Date: Jan 2008
Location: England, UK
Posts: 83
Thanks: 3
Ross is on a distinguished road
Default 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,
__________________
Ross » Blog » Twitter
Ross is offline  
Reply With Quote
Old 01-17-2009, 11:13 AM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,324
Thanks: 5
Salathe is on a distinguished road
Default

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.
Salathe is offline  
Reply With Quote
Old 01-17-2009, 11:44 AM   #3 (permalink)
The Contributor
 
Ross's Avatar
 
Join Date: Jan 2008
Location: England, UK
Posts: 83
Thanks: 3
Ross is on a distinguished road
Default

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.
__________________
Ross » Blog » Twitter
Ross is offline  
Reply With Quote
Old 01-17-2009, 12:05 PM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,324
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Ross View Post
are we planning to take advantage of PHP5's class/interface autoloading?
I do hope so.

Quote:
Originally Posted by Ross View Post
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 View Post
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.
Salathe is offline  
Reply With Quote
Old 01-17-2009, 03:24 PM   #5 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,296
Thanks: 17
Village Idiot is on a distinguished road
Default

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

Village Idiot is offline  
Reply With Quote
Old 01-17-2009, 03:32 PM   #6 (permalink)
The Contributor
 
Ross's Avatar
 
Join Date: Jan 2008
Location: England, UK
Posts: 83
Thanks: 3
Ross is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
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.
__________________
Ross » Blog » Twitter
Ross is offline  
Reply With Quote
Old 01-17-2009, 07:49 PM   #7 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,296
Thanks: 17
Village Idiot is on a distinguished road
Default

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

Village Idiot is offline  
Reply With Quote
Old 01-17-2009, 10:01 PM   #8 (permalink)
The Contributor
 
Ross's Avatar
 
Join Date: Jan 2008
Location: England, UK
Posts: 83
Thanks: 3
Ross is on a distinguished road
Default

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
__________________
Ross » Blog » Twitter
Ross is offline  
Reply With Quote
Old 01-17-2009, 10:22 PM   #9 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,296
Thanks: 17
Village Idiot is on a distinguished road
Default

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

Village Idiot is offline  
Reply With Quote
Old 06-03-2010, 05:37 AM   #10 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 8
Thanks: 0
infonama is on a distinguished road
Default

Agree with Village Idiot. the cleaner the better.
__________________
Latest News
Download Free Songs
infonama is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Several Questions - Security and Performance Killswitch General 0 12-09-2008 03:10 AM
PHP Contact Form - 2 Questions ncmason General 0 05-26-2008 03:38 AM
Zend Framework - questions questions abiko Advanced PHP Programming 4 02-29-2008 12:46 AM
Dozens of questions which I cannot find. v_v Orc MySQL & Databases 11 01-31-2008 07:50 PM
A Few AJAX Questions Gurnk Javascript, AJAX, E4X 4 10-23-2007 12:30 PM


All times are GMT. The time now is 06:42 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design