|
@@ -163,20 +163,20 @@
|
|
|
<title>Abstract Classes</title>
|
|
<title>Abstract Classes</title>
|
|
|
|
|
|
|
|
<para>
|
|
<para>
|
|
|
- In general, abstract classes follow the same conventions as <link
|
|
|
|
|
|
|
+ In general, abstract classes follow the same conventions as <link
|
|
|
linkend="coding-standard.naming-conventions.classes">classes</link>,
|
|
linkend="coding-standard.naming-conventions.classes">classes</link>,
|
|
|
- with one additional rule: abstract class names must end in the term, "Abstract",
|
|
|
|
|
|
|
+ with one additional rule: abstract class names must end in the term, "Abstract",
|
|
|
and that term must not be preceded by an underscore. As an example,
|
|
and that term must not be preceded by an underscore. As an example,
|
|
|
- <classname>Zend_Controller_Plugin_Abstract</classname> is considered an
|
|
|
|
|
|
|
+ <classname>Zend_Controller_Plugin_Abstract</classname> is considered an
|
|
|
invalid name, but <classname>Zend_Controller_PluginAbstract</classname> or
|
|
invalid name, but <classname>Zend_Controller_PluginAbstract</classname> or
|
|
|
- <classname>Zend_Controller_Plugin_PluginAbstract</classname> would be valid
|
|
|
|
|
|
|
+ <classname>Zend_Controller_Plugin_PluginAbstract</classname> would be valid
|
|
|
names.
|
|
names.
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
|
<note>
|
|
<note>
|
|
|
<para>
|
|
<para>
|
|
|
- This naming convention is new with version 1.9.0 of Zend Framework. Classes
|
|
|
|
|
- that pre-date that version may not follow this rule, but will be renamed in
|
|
|
|
|
|
|
+ This naming convention is new with version 1.9.0 of Zend Framework. Classes
|
|
|
|
|
+ that pre-date that version may not follow this rule, but will be renamed in
|
|
|
the future in order to comply.
|
|
the future in order to comply.
|
|
|
</para>
|
|
</para>
|
|
|
</note>
|
|
</note>
|
|
@@ -186,26 +186,26 @@
|
|
|
<title>Interfaces</title>
|
|
<title>Interfaces</title>
|
|
|
|
|
|
|
|
<para>
|
|
<para>
|
|
|
- In general, interfaces follow the same conventions as <link
|
|
|
|
|
|
|
+ In general, interfaces follow the same conventions as <link
|
|
|
linkend="coding-standard.naming-conventions.classes">classes</link>,
|
|
linkend="coding-standard.naming-conventions.classes">classes</link>,
|
|
|
- with one additional rule: interface names may optionally end in the term,
|
|
|
|
|
|
|
+ with one additional rule: interface names may optionally end in the term,
|
|
|
"Interface", but that term must not be preceded by an underscore. As an example,
|
|
"Interface", but that term must not be preceded by an underscore. As an example,
|
|
|
- <classname>Zend_Controller_Plugin_Interface</classname> is considered an
|
|
|
|
|
|
|
+ <classname>Zend_Controller_Plugin_Interface</classname> is considered an
|
|
|
invalid name, but <classname>Zend_Controller_PluginInterface</classname> or
|
|
invalid name, but <classname>Zend_Controller_PluginInterface</classname> or
|
|
|
- <classname>Zend_Controller_Plugin_PluginInterface</classname> would be valid
|
|
|
|
|
|
|
+ <classname>Zend_Controller_Plugin_PluginInterface</classname> would be valid
|
|
|
names.
|
|
names.
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
<para>
|
|
|
- While this rule is not required, it is strongly recommended, as it provides a
|
|
|
|
|
- good visual cue to developers as to which files contain interfaces rather than
|
|
|
|
|
|
|
+ While this rule is not required, it is strongly recommended, as it provides a
|
|
|
|
|
+ good visual cue to developers as to which files contain interfaces rather than
|
|
|
classes.
|
|
classes.
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
|
<note>
|
|
<note>
|
|
|
<para>
|
|
<para>
|
|
|
- This naming convention is new with version 1.9.0 of Zend Framework. Classes
|
|
|
|
|
- that pre-date that version may not follow this rule, but will be renamed in
|
|
|
|
|
|
|
+ This naming convention is new with version 1.9.0 of Zend Framework. Classes
|
|
|
|
|
+ that pre-date that version may not follow this rule, but will be renamed in
|
|
|
the future in order to comply.
|
|
the future in order to comply.
|
|
|
</para>
|
|
</para>
|
|
|
</note>
|
|
</note>
|
|
@@ -478,10 +478,10 @@ $sampleArray = array(1, 2, 3, 'Zend', 'Studio',
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
<para>
|
|
|
- Alternately, the initial array item may begin on the following line. If so,
|
|
|
|
|
- it should be padded at one indentation level greater than the line containing
|
|
|
|
|
|
|
+ Alternately, the initial array item may begin on the following line. If so,
|
|
|
|
|
+ it should be padded at one indentation level greater than the line containing
|
|
|
the array declaration, and all successive lines should have the same
|
|
the array declaration, and all successive lines should have the same
|
|
|
- indentation; the closing paren should be on a line by itself at the same
|
|
|
|
|
|
|
+ indentation; the closing paren should be on a line by itself at the same
|
|
|
indentation level as the line containing the array declaration:
|
|
indentation level as the line containing the array declaration:
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
@@ -494,9 +494,9 @@ $sampleArray = array(
|
|
|
]]></programlisting>
|
|
]]></programlisting>
|
|
|
|
|
|
|
|
<para>
|
|
<para>
|
|
|
- When using this latter declaration, we encourage using a trailing comma for
|
|
|
|
|
- the last item in the array; this minimizes the impact of adding new items on
|
|
|
|
|
- successive lines, and helps to ensure no parse errors occur due to a missing
|
|
|
|
|
|
|
+ When using this latter declaration, we encourage using a trailing comma for
|
|
|
|
|
+ the last item in the array; this minimizes the impact of adding new items on
|
|
|
|
|
+ successive lines, and helps to ensure no parse errors occur due to a missing
|
|
|
comma.
|
|
comma.
|
|
|
</para>
|
|
</para>
|
|
|
</sect3>
|
|
</sect3>
|
|
@@ -516,12 +516,12 @@ $sampleArray = array('firstKey' => 'firstValue',
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
<para>
|
|
|
- Alternately, the initial array item may begin on the following line. If so,
|
|
|
|
|
- it should be padded at one indentation level greater than the line containing
|
|
|
|
|
|
|
+ Alternately, the initial array item may begin on the following line. If so,
|
|
|
|
|
+ it should be padded at one indentation level greater than the line containing
|
|
|
the array declaration, and all successive lines should have the same
|
|
the array declaration, and all successive lines should have the same
|
|
|
- indentation; the closing paren should be on a line by itself at the same
|
|
|
|
|
- indentation level as the line containing the array declaration. For
|
|
|
|
|
- readability, the various "=>" assignment operators should be padded such that
|
|
|
|
|
|
|
+ indentation; the closing paren should be on a line by itself at the same
|
|
|
|
|
+ indentation level as the line containing the array declaration. For
|
|
|
|
|
+ readability, the various "=>" assignment operators should be padded such that
|
|
|
they align.
|
|
they align.
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
@@ -533,9 +533,9 @@ $sampleArray = array(
|
|
|
]]></programlisting>
|
|
]]></programlisting>
|
|
|
|
|
|
|
|
<para>
|
|
<para>
|
|
|
- When using this latter declaration, we encourage using a trailing comma for
|
|
|
|
|
- the last item in the array; this minimizes the impact of adding new items on
|
|
|
|
|
- successive lines, and helps to ensure no parse errors occur due to a missing
|
|
|
|
|
|
|
+ When using this latter declaration, we encourage using a trailing comma for
|
|
|
|
|
+ the last item in the array; this minimizes the impact of adding new items on
|
|
|
|
|
+ successive lines, and helps to ensure no parse errors occur due to a missing
|
|
|
comma.
|
|
comma.
|
|
|
</para>
|
|
</para>
|
|
|
</sect3>
|
|
</sect3>
|
|
@@ -587,7 +587,7 @@ class SampleClass
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
<para>
|
|
|
- Classes that extend other classes or which implement interfaces should
|
|
|
|
|
|
|
+ Classes that extend other classes or which implement interfaces should
|
|
|
declare their dependencies on the same line when possible.
|
|
declare their dependencies on the same line when possible.
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
@@ -599,13 +599,13 @@ class SampleClass extends FooAbstract implements BarInterface
|
|
|
|
|
|
|
|
<para>
|
|
<para>
|
|
|
If as a result of such declarations, the line length exceeds the <link
|
|
If as a result of such declarations, the line length exceeds the <link
|
|
|
- linkend="coding-standard.php-file-formatting.max-line-length">maximum line
|
|
|
|
|
- length</link>, break the line before the "extends" and/or "implements"
|
|
|
|
|
|
|
+ linkend="coding-standard.php-file-formatting.max-line-length">maximum line
|
|
|
|
|
+ length</link>, break the line before the "extends" and/or "implements"
|
|
|
keywords, and pad those lines by one indentation level.
|
|
keywords, and pad those lines by one indentation level.
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
|
<programlisting language="php"><![CDATA[
|
|
<programlisting language="php"><![CDATA[
|
|
|
-class SampleClass
|
|
|
|
|
|
|
+class SampleClass
|
|
|
extends FooAbstract
|
|
extends FooAbstract
|
|
|
implements BarInterface
|
|
implements BarInterface
|
|
|
{
|
|
{
|
|
@@ -613,13 +613,13 @@ class SampleClass
|
|
|
]]></programlisting>
|
|
]]></programlisting>
|
|
|
|
|
|
|
|
<para>
|
|
<para>
|
|
|
- If the class implements multiple interfaces and the declaration exceeds the
|
|
|
|
|
- maximum line length, break after each comma separating the interfaces, and
|
|
|
|
|
|
|
+ If the class implements multiple interfaces and the declaration exceeds the
|
|
|
|
|
+ maximum line length, break after each comma separating the interfaces, and
|
|
|
indent the interface names such that they align.
|
|
indent the interface names such that they align.
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
|
<programlisting language="php"><![CDATA[
|
|
<programlisting language="php"><![CDATA[
|
|
|
-class SampleClass
|
|
|
|
|
|
|
+class SampleClass
|
|
|
implements BarInterface,
|
|
implements BarInterface,
|
|
|
BazInterface
|
|
BazInterface
|
|
|
{
|
|
{
|
|
@@ -697,14 +697,14 @@ class Foo
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
<para>
|
|
|
- In cases where the argument list exceeds the <link
|
|
|
|
|
- linkend="coding-standard.php-file-formatting.max-line-length">maximum line
|
|
|
|
|
- length</link>, you may introduce line breaks. Additional arguments to the
|
|
|
|
|
- function or method must be indented one additional level beyond the function
|
|
|
|
|
- or method declaration. A line break should then occur before the closing
|
|
|
|
|
- argument paren, which should then be placed on the same line as the opening
|
|
|
|
|
- brace of the function or method with one space separating the two, and at the
|
|
|
|
|
- same indentation level as the function or method declaration. The following is
|
|
|
|
|
|
|
+ In cases where the argument list exceeds the <link
|
|
|
|
|
+ linkend="coding-standard.php-file-formatting.max-line-length">maximum line
|
|
|
|
|
+ length</link>, you may introduce line breaks. Additional arguments to the
|
|
|
|
|
+ function or method must be indented one additional level beyond the function
|
|
|
|
|
+ or method declaration. A line break should then occur before the closing
|
|
|
|
|
+ argument paren, which should then be placed on the same line as the opening
|
|
|
|
|
+ brace of the function or method with one space separating the two, and at the
|
|
|
|
|
+ same indentation level as the function or method declaration. The following is
|
|
|
an example of one such situation:
|
|
an example of one such situation:
|
|
|
|
|
|
|
|
<programlisting language="php"><![CDATA[
|
|
<programlisting language="php"><![CDATA[
|
|
@@ -844,26 +844,26 @@ if ($a != 2) {
|
|
|
|
|
|
|
|
<para>
|
|
<para>
|
|
|
If the conditional statement causes the line length to exceed the <link
|
|
If the conditional statement causes the line length to exceed the <link
|
|
|
- linkend="coding-standard.php-file-formatting.max-line-length">maximum line
|
|
|
|
|
- length</link> and has several clauses, you may break the conditional into
|
|
|
|
|
- multiple lines. In such a case, break the line prior to a logic operator, and
|
|
|
|
|
- pad the line such that it aligns under the first character of the conditional
|
|
|
|
|
- clause. The closing paren in the conditional will then be placed on a line with
|
|
|
|
|
- the opening brace, with one space separating the two, at an indentation level
|
|
|
|
|
|
|
+ linkend="coding-standard.php-file-formatting.max-line-length">maximum line
|
|
|
|
|
+ length</link> and has several clauses, you may break the conditional into
|
|
|
|
|
+ multiple lines. In such a case, break the line prior to a logic operator, and
|
|
|
|
|
+ pad the line such that it aligns under the first character of the conditional
|
|
|
|
|
+ clause. The closing paren in the conditional will then be placed on a line with
|
|
|
|
|
+ the opening brace, with one space separating the two, at an indentation level
|
|
|
equivalent to the opening control statement.
|
|
equivalent to the opening control statement.
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
|
<programlisting language="php"><![CDATA[
|
|
<programlisting language="php"><![CDATA[
|
|
|
-if (($a == $b)
|
|
|
|
|
|
|
+if (($a == $b)
|
|
|
&& ($b == $c)
|
|
&& ($b == $c)
|
|
|
|| (Foo::CONST == $d)
|
|
|| (Foo::CONST == $d)
|
|
|
) {
|
|
) {
|
|
|
$a = $d;
|
|
$a = $d;
|
|
|
}
|
|
}
|
|
|
]]></programlisting>
|
|
]]></programlisting>
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
<para>
|
|
<para>
|
|
|
- The intention of this latter declaration format is to prevent issues when
|
|
|
|
|
|
|
+ The intention of this latter declaration format is to prevent issues when
|
|
|
adding or removing clauses from the conditional during later revisions.
|
|
adding or removing clauses from the conditional during later revisions.
|
|
|
</para>
|
|
</para>
|
|
|
|
|
|
|
@@ -886,7 +886,7 @@ if ($a != 2) {
|
|
|
$a = 7;
|
|
$a = 7;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-if (($a == $b)
|
|
|
|
|
|
|
+if (($a == $b)
|
|
|
&& ($b == $c)
|
|
&& ($b == $c)
|
|
|
|| (Foo::CONST == $d)
|
|
|| (Foo::CONST == $d)
|
|
|
) {
|
|
) {
|