Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AA Best Practices & Learning Resources

PHP The Right Way Must read


Writing Super Readable Code

Best Practices For Modern PHP Development Valid points

30 PHP Best Practices Older but most of "practices" are still relevant, couple of "code review" related advices as well

20+ PHP Best Practices to Follow Some of those mentioned previously but repeating but "repetitio est mater studiorum"

PHP Best Practices Selection of PHP tips among different areas (best practices is not the right name but still usefull)


Most Common Mistakes PHP Developers Make

7 More Mistakes Commonly Made by PHP Developers

Critical Oversights in Web Development


Code review guidelines Tips both for developers and reviewers + short checklists (some points java specific)


PHP Security Cheatsheet


Intro to functional programming


Zdrojak.cz

Devel.cz


Some code review tips (apply when writing software as well)

  • implement the design completely and correctly
  • handle reasonable error conditions
  • follow PSR coding standard (naming, indentation, white spaces usage etc...)
  • regularly commit (sizeable but working changes) so the code reviews are not complex and long
  • write unit tests
  • do peer code reviews
  • remove any code duplicities (extract repeated code blocks to a method or procedure)
  • less code is better (try to use functions instead of loops)
  • beware of deep nesting (conditions, loops), preferably nest only 1-2 levels
  • create well-structured code, consistent in style and formatting
  • get rid of all leftover stubs, test routines and any unnecessary code (dead code) or testing code
  • get rid of all redudant / unused variables
  • name the variables, constants, procedures, classes and methods in a descriptive way (meaningful, consistent and clear names)
  • do not use (hardcoded) magic numbers or strings, instead use variables, config options or constants
  • use OOP principles when applicable (interface, trait, abstractions, static)
  • keep functions outside of loops
  • do not copy extra variables
  • follow DRY principle
  • use array literals "[" .. "]", instead of array(..)
  • use proper directory structure and separate the code into files

We'll add some other points later related to data sanitization, design patterns etc.

@peterturza

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.