Reasons and background of different rules

81 views
Skip to first unread message

Wijnand Velzel

unread,
Mar 9, 2015, 9:45:22 AM3/9/15
to php-f...@googlegroups.com

Hi all,

We are starting with php/web development in our office and will potentially develop a lot more in php.
For this reason I was browsing for coding guidelines and standards for php develpment and found http://www.php-fig.org/.
Although the recommendations intuitively feel good, and I will most likely adopt the coding standards, I am looking for the reasons behind the rules and guidelines.
Are the reasons documented somewhere?

For now I am looking at PSR1- 2.3. Side Effects.

Regards,
  Wijnand


Larry Garfield

unread,
Mar 9, 2015, 11:05:57 AM3/9/15
to php-f...@googlegroups.com
For most of PSR-2, the answer is "because surveys said that would piss
off the fewest number of people".

For PSR-1, the answer is mostly "because that minimizes environmental
differences between servers".

For Side Effects in particular, there are cases where you want to run
code by including a file. There are other cases where you want to
define new functions/classes/constants by including a file. Those mix
badly.

If you have a file that contains both "executable" statements and new
symbol definitions (functions and classes), that executable code is now
run-once. Trying to run it a second time will cause a fatal error.
Since you can't guarantee when someone else may legitimately want to run
that executable code multiple times, it's good practice to not take that
ability away from them. That means keeping symbol definition separate
from executing code so that other people can mix and match as they feel
is appropriate, not as you feel is expected. It also helps with
testing, too, for the same reason.

--Larry Garfield
Reply all
Reply to author
Forward
0 new messages