[task/coding-guidelines] Added a section about class names.

The class naming / autoloading RFC is located on area51:
    http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=33237

PHPBB3-9557
This commit is contained in:
Nils Adermann 2010-07-03 15:41:09 +02:00
parent 163a0974a3
commit e7cc707931

View file

@ -333,7 +333,33 @@ for ($i = 0; $i < $outer_size; $i++)
<h4>Class Names:</h4> <h4>Class Names:</h4>
<p>Apart from following the rules for function names, all classes should be prefixed with <strong>phpbb_</strong> to avoid name clashes.</p> <p>Apart from following the rules for function names, all classes should meet the following conditions:</p>
<ul>
<li>Every class must be defined in a separate file.</li>
<li>The classes have to be located in a subdirectory of <code>includes/</code>.</li>
<li>Classnames to be prefixed with <code>phpbb_</code> to avoid name clashes, the filename should not contain the prefix.</li>
<li>Class names have to reflect the location of the file they are defined in. The longest list of prefixes, separated by underscores, which is a valid path must be the directory in which the file is located. So the directory names must not contain any underscores, but the filename may. If the filename would be empty the last directory name is used for the filename as well.</li>
<li>Directories should typically be a singular noun (e.g. <code>dir</code> in the example below, not <code>dirs</code>.</li>
</ul>
<p>So given the following example directory structure you would result in the below listed lookups</p>
<div class="codebox"><pre>
includes/
class_name.php
dir/
class_name.php
dir.php
subdir/
class_name.php
</pre></div>
<div class="codebox"><pre>
phpbb_class_name - includes/class_name.php
phpbb_dir_class_name - includes/dir/class_name.php
phpbb_dir - includes/dir/dir.php
phpbb_dir_subdir_class_name - includes/dir/subdir/class_name.php
</pre></div>
<h4>Summary:</h4> <h4>Summary:</h4>
<p>The basic philosophy here is to not hurt code clarity for the sake of laziness. This has to be balanced by a little bit of common sense, though; <code>print_login_status_for_a_given_user()</code> goes too far, for example -- that function would be better named <code>print_user_login_status()</code>, or just <code>print_login_status()</code>.</p> <p>The basic philosophy here is to not hurt code clarity for the sake of laziness. This has to be balanced by a little bit of common sense, though; <code>print_login_status_for_a_given_user()</code> goes too far, for example -- that function would be better named <code>print_user_login_status()</code>, or just <code>print_login_status()</code>.</p>