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:
- 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
- Explicitly load what you need over autoloaders
- Autoloaders are complex and can fail. Just
include_once()
what you need
- 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
- 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.
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', '[email protected]');
// 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();
}
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 -.-
Besides from the fact that this is meant as a joke, and besides the suppression of errors, this is actually how you make a really slim and performant application. No ridiculous framework abstraction crap and no OOP layer.
The only people who need OOP are people who are afraid of procedural code, not because procedural is bad, but because they have no clue how to handle it or do it right.
OOP has a hype machine behind it, it was nothing more than a stupid idea on a piece of paper that actually in it's original requires a psychologist!
Get it right: https://www.youtube.com/watch?v=ZrBQmIDdls4