Skip to content

Instantly share code, notes, and snippets.

@InFog
Last active March 23, 2023 08:15
Show Gist options
  • Save InFog/2d5be2b1b4dd818333f6 to your computer and use it in GitHub Desktop.
Save InFog/2d5be2b1b4dd818333f6 to your computer and use it in GitHub Desktop.
PHP Procedural Framework Manifesto

Procedural PHP Manifesto

We are web site developers (a.k.a. webmasters) and we just want to get stuff done. We don't need Object Orientation and we don't need Design Patters and other boring and not easy to learn and understand stuff to get in our way to get our sites up and running.

And that's why our values are:

  1. Procedural Code over Object Orientation
  • No one actually needs OO to develop web applications
  • Classes with only static functions are ok, since it's just a way to keep functions in one place. And is still procedural
  1. Explicitly load what you need over autoloaders
  • Autoloaders are complex and can fail. Just include_once() what you need
  1. One PHP file per URL over Front Controller
  • Just include_once() header.inc.php and footer.inc.php in your files and everything will be ok
  • And also, Front Controller reminds us of Controllers and MVC and this stuff is complicated
  1. Inline MySQL queries over Database Abstraction libraries
  • These libraries are usually OO, and we don't like OO

And remember that we don't only give more value to the items on the left, we simply choose to ignore the values on the right.

PHP Procedural Framework

To make our dreams come true, we developed our own PHP Procedural Framework. This is the simplest PHP Framework around because we have no time to learn how to use the huge OO-DependencyInjection monsters that surround us.

The framework is contained within just one file that you can include_once() in all your scripts (value #3):

<?php
include('phpprocedural.inc.php');

And that's all, super simple! Now you can use the life saving functions:

<?php
connect_to_mysql();
// In the first lines of 'phpprocedural.inc.php' you will find the config vars for connection

include_script('header.php');
// This function checks if the file exists, if not it shows an error

show_webmaster('John Doe', 'webmaster@phpproceduralmanifesto.com');
// Use this in the footer of the site. Displays something like this: Webmaster John Doe - ©Year - Visit Counter: 000004356
// How can we count the visits? Don't worry, we just can ;)

gracefully_close_mysql_connection();
// Will close MySQL connections. We don't want open connections to me left there, right?

You can open 'phpprocedural.inc.php' to read our code, but you don't need to. Our code is simple and awesome. Here is just a small part, if you want to know about our best practices:

<?php
function gracefully_close_mysql_connection() {
    // A friend told me that '@' will avoid errors when there is no MySQL connections. Great!
    @ mysql_close();
}

Bonus! No more errors, now you can become a PHP Pro in no time!

We all know that errors in the code, like undefined array keys, are boring and only confusing for our clients and users. In the last version of our framework we added some magical lines that will make you a PHP Pro with no more errors showing up in no time!

Here is how the magic is done:

<?php
// Magically removes errors from the code
@ error_reporting(0);
@ ini_set('error_reporting', 0);
@ ini_set('display_errors', false);

Join us! Spread the word! Use the tag #proceduralphp :)

PS: This is just a joke -.-

@InFog
Copy link
Author

InFog commented Mar 23, 2023

This is gold. Thanks for sharing, @tbreuss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment