A modern PHP example

  1. Goals
  2. Code structure
  3. CRUD lifecycle
  4. Comments

Work in progress

There are thousands PHP tutorials out there, an new ones coming out every day. Sadly, but many of them only contribute to PHP's bad reputation, never adhering to basic coding standards or even basic security guidelines.

Goals

My aim is to provide a reference plain PHP code example, that adheres to many important standards and practices that are obligatory in the modern programming:

My main goal however, my deepest desire is to show that a properly written code is no more complex than quick and dirty solutions, but on the contrary, being simpler and easier to write and read.

Code structure

Each generic PHP script must be split into four parts:

  1. Initialization (usually it's done in a separate file that's either includes the current script, or being included into it)
  2. Input data validation (if there is any input)
  3. Data manipulation
  4. Output (if any)

Even modern frameworks follow this separation, although never within the same file, but these parts always can be distinguished in the code.

CRUD lifecycle

Each generic PHP script that interactively processes user data, such as a registration form, should follow the below structure

Source code: https://github.com/colshrapnel/modern_raw_php_examle


Related articles: