Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Zend Framework coding standard, which is the more readable approach?

This is an subjective question, I need your feels and thoughts about coding standards, and formatting practices.

PHP Zend coding standard requires to write multiline function calls like this:

$returnedValue = $object->longMethodName(
    $argument1,
    $otherArgument,
    42
);

I think the following approach is more readable:

$returnedValue = $object->longMethodName($argument1,
                                         $otherArgument,
                                         42);

Becouse the there is only one line on the left side, this indicates this is only one statement, and the arguments are closer to the method name.

Which one do YOU prefer?

like image 814
erenon Avatar asked Mar 04 '10 20:03

erenon


People also ask

Which design pattern best describes the Zend Framework?

Aspect Oriented Design pattern.

What is the use of Zend framework in PHP?

Zend Framework is a collection of professional PHP packages with more than 570 million installations. It can be used to develop web applications and services using PHP 5.6+, and provides 100% object-oriented code using a broad spectrum of language features.

Is Zend Framework Good?

The Zend framework makes web development easy, and can complete tasks quickly and efficiently. The ZF doesn't come as a whole unit that doesn't budge at all. It is decoupled, meaning the components come as an individual library , so the developers need to load only the required components.

Is Zend a PHP framework?

Zend is an open source PHP framework. It is pure object-oriented and built around the MVC design pattern. Zend framework contains collection of PHP packages which can be used to develop web applications and services. Zend was started by Andi Gutmans and Zeev Suraski.


1 Answers

The second approach leaves you with one additional Problem: Line length. The Zend Coding Standard suggest that "The maximum length of any line of PHP code is 120 characters."

This means if you want good (long, descriptive) Variables names and you happen to have one for the return value, the object, a good named function and a long parameter you are much more likely to hit that 120 chars limit.

Adding to that and depending on your standard the max length may be only 80 Chars or something in between.

Additionally i like the first one better if used repeatedly

$returnedValue = $object->longMethodName(
    $argument1,
    $otherArgument,
    42
);
$returnedValue = $object->longMethodName(
    $argument1,
    $otherArgument,
    42
);
$returnedValue = $object->longMethodName(
    $argument1,
    $otherArgument,
    42
);
$returnedValue = $object->longMethodName(
    $argument1,
    $otherArgument,
    42
);

$returnedValue = $object->longMethodName($argument1,
                                         $otherArgument,
                                         42);
$returnedValue = $object->longMethodName($argument1,
                                         $otherArgument,
                                         42);
$returnedValue = $object->longMethodName($argument1,
                                         $otherArgument,
                                         42);
$returnedValue = $object->longMethodName($argument1,
                                         $otherArgument,
                                         42);

Like Pekka said, less eye jumping.

like image 134
edorian Avatar answered Oct 05 '22 17:10

edorian