The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

+ Works with autoload (debated below).
+ Groups consts into more manageable units.
- I have to update all calls using Class::function()
- Classes require more resources to instantiate, even if static.

2) I put all common classes into a single file and include that outright. These include the applications controllers, filters and base classes for commands, requests and views, as well as a few utility classes. My include folder looks like this:

All stock stuff is included by default, but I need a way to handle third party addons, which in reality shouldn't total that many. The plugins drop their commands, requests and views into the right folders.

Which of these should I do?

A) Use autload to catch all addon code?

+ Simple and relatively quick.
+ No need to modify existing code when a plugin is added.
- More file reads (how many is unknown but expected to be low)

B) Put all of a particular plugins classes into a single file, and add a Plugin registry to the base app, which loads all plugins and initializes things by calling a new Registrant class in the plugin code?

+ Less file reads.
- More code than I really wanted, but can live with it.
- Loads classes that may, or may not be used.
- Bigger plugin files and an extra class.

Ok, let's get through these and I'll see if there's anything else I need to ask. Thanks in advance for your comments and opinions.

Easily included. - RIGHT
Easily ported. - RIGHT
Not OO - RIGHT, but they are to be used globally, so => WRONG
Breaks my file naming strategy - RIGHT, but usually the file naming strategy is not so important, as the class naming conventions.

Sorry, I'm having problems understanding if RIGHT is being said in a sarcastic way or not. I will assume not as I'm an optimist. To be sure though, if this were your app, you'd include a procedural file?

Sorry, I'm having problems understanding if RIGHT is being said in a sarcastic way or not. I will assume not as I'm an optimist. To be sure though, if this were your app, you'd include a procedural file?

I think REMIYA is sugessting you to use the option A, and I whole heartedly agree. With an already overcrowded global namespace in PHP, a few more functions are not a problem, especially if they really are used globally.

PHP is not Java, where everything has to be in one class or another. Use the language to its best.

(Note: I'm not saying that Java's approach is wrong or inferior to PHP's -- they're just different.)

I agree with BerislavLopac. IIRC there are about 1500 defined functions available in PHP. Take a look at the function overview. I don't think using a bunch of your own would really break nor hurt any concept at all, specially when they're not related to any concrete object in your application.

Sorry, I'm having problems understanding if RIGHT is being said in a sarcastic way or not. I will assume not as I'm an optimist. To be sure though, if this were your app, you'd include a procedural file?

Sarcasm has nothing to do right here!

Well, I'd include procedural file, for some reasons. Let me take for example the String functions in PHP. They are all procedural. What if I want to make a new functon for it? Do I have to make a new class (i.e. myString), and then attach the new function as a method to that class? Of course not? Instead of making my programming easier, it would just slow it unnecesarily down.

A quick example:
1. A function I needed later was to check the ending of a string. So I created a new function ends_with(string str, string ending).
2. I placed it in a file called string.functions.php.
3. Now I just include it with require_once('string.functions.php'); and the function is ready to be used as any build-in php function.

/**
* Extracts the extension from the given string.
* Extension is any characters after the final dot.
* @param $string String (usually a filename or path) from which to extract the extension.
* @return String containing the extension.
*/
function ext($string)
{
return strtolower(substr($string, strrpos($string, '.') + 1));
}

/**
* Takes the fields of a HTML form and sends them to the given address.
* The fields are formatted as "field_name: field_contents", with each field on a new line.
* Any underscores in the field names are converted to spaces.
* @param $to String containing the email address to send the form to.
* Multiple addresses may be separated by a comma, just as per the mail() function.
* @param $subject String containing the subject of the mail message.
* @param $fields Associative array, usually $_POST or $_REQUEST,
* having field names as keys and contents as values.
* If a field contains multiple values (i.e. is an array), the values
* are separated by a comma.
* @param $skip Array of field names that are not to be included in the mail.
* @param $headers String or array containing the additional headers.
* If an array, the headers should be defined as "header_name => header_value".
* If a string, the headers should be written as "header_name: header_value\r\n".
* @return Boolean Return of the mail() function.
*/
function send_mailform($to, $subject, $fields, $skip = false, $headers = '') {
$skip = $skip ? $skip : array();
$message = "$subject\n----------------------------------------------------------\n\n";
foreach($fields as $field => $value) {
if(!in_array($field, $skip)) {
$value = is_array($value) ? implode(", ", $value) : $value;
$message .= ul2sp($field) .": $value\n";
}
}
$header_string = '';
if(is_array($headers)) {
foreach($headers as $header => $contents) {
$header_string .= "$header: $contents\r\n";
}
}
else {
$header_string = $headers;
}
return mail($to, $subject, $message, $header_string);
}