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>

<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"
<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

<h2>Abstract Classes</h2>

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


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


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