ZF-503: Class Member Organizational Conventions


Ralph Schindler proposed a series of class member organizational conventions that we can adopt for improving the readability and consistency of the framework code base. I've modified them slightly for clarity and to include others' responses to the mailing list thread:…

Properties should appear at the top of the class definition followed by methods.

Class members (both properties and methods) should be organized by visibility: {{public}} first, {{protected}} second, and {{private}} last.

Special methods such as {{__construct()}}, {{__destruct()}}, {{__clone()}}, {{__sleep()}}, {{__wakeup()}}, {{__get()}}, {{__set()}}, {{__isset()}}, {{__isset()}}, {{__unset()}}, {{__call()}}, {{__toString()}}, and {{__set_state()}} should appear first in the list of methods, in the order presented here, as needed by the class.

Static methods should be listed before instance methods.

Static methods should have the visibility written first, as illustrated in the php manual at []:

public static $myStatic = 'foo';
public static function aStaticMethod()

Finally, methods should be grouped logically by execution order, developer need, etc., where appropriate. For example: {{setOptions()}} appears before {{start()}}, which appears before {{stop()}}, since this is the most logical order of usage.


We currently have a rift on this issues as wether visibility comes before static or not. We should all voice our opinion on the matter, as i see this is more a matter of taste than objective fact, and based off what has been brought up, come to a decision on this.. perhaps have a hammer come down from the powers that be.. Bill? Hehe.

But seriously, lets get this decided and put into the coding standards doc.

We all want fresh and clean code :)

This issue should have been fixed for the 1.5 release.

This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.

Please evaluate and categorize/assign as necessary.

Updating project management info.

Updating to comply with new IT component conventions.

Assigning to matthew.

Closing as not an issue. ZF1 is near end of production/new features, and focus will now be on ZF2 for coding conventions, etc.