View Source

<h1>Coding Standard decisions for 5.3</h1>

<p>Based on the polls issued this week, we're going to make the following addendums to our coding standards:</p>

<h2>Namespace Aliases</h2>

<p>PHP 5.3 introduces namespaces. Part of namespace support is the ability to alias namespaces and/or members of namespaces with the &quot;use&quot; annotation.</p>

<p>When aliasing within ZF library code, the aliases should typically follow these patterns:</p>

<ul>
<li>If aliasing a namespace, use the final segment of the namespace; this can be accomplished by simply omitting the &quot;as&quot; portion of the alias:
<ac:macro ac:name="code"><ac:default-parameter>php</ac:default-parameter><ac:plain-text-body><![CDATA[
use Zend\Filter; // Alias is then "Filter"
use Zend\Form\Element; // Alias is "Element"
]]></ac:plain-text-body></ac:macro></li>
<li>If aliasing a class, either use the class name (no &quot;as&quot; clause), or suffix the class with the subcomponent namespace preceding it:
<ac:macro ac:name="code"><ac:default-parameter>php</ac:default-parameter><ac:plain-text-body><![CDATA[
use Zend\Controller\Action\HelperBroker; // aliased as "HelperBroker"
use Zend\Filter\Int as IntFilter; // using suffix
]]></ac:plain-text-body></ac:macro></li>
</ul>


<h2>Abstract Classes</h2>

<p>Abstract classes will be prefixed with the word &quot;Abstract&quot;: AbstractController, AbstractForm, etc.</p>

<h2>Interfaces</h2>

<p>Interfaces should be named descriptively and sufficiently generically to ensure they do not conflict with concrete implementations while still accurately indicating the purpose of the interface. Examples include:</p>

<ul>
<li>Configurable</li>
<li>Adaptable</li>
<li>Resource</li>
<li>Role</li>
<li>Loadable</li>
<li>Builder</li>
</ul>


<h2>Type Hinting</h2>

<p>Type hints will use available aliases (as declared using &quot;use&quot; statements) whenever possible. If a classname appears only once within the scope of the defined class, a fully qualified name may be used, but we strongly encourage defining an alias to facilitate documentation of dependencies.</p>