Skip to content

Instantly share code, notes, and snippets.

@InFog
Last active March 23, 2023 08:15
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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 -.-

@e7o-de
Copy link

e7o-de commented Jul 6, 2017

/sign.

Actually, "One PHP file per URL over Front Controller" is the thing Symfony is doing as well, but they're putting a lot of magic around which breaks from time to time ... ;)

@lotfio
Copy link

lotfio commented Jul 30, 2017

I thought You are seriously talking

@d3y4n
Copy link

d3y4n commented Oct 30, 2017

Would be nice to implement this https://github.com/p-h-p/boostrap.php

@InFog
Copy link
Author

InFog commented Oct 30, 2017

I approve the usage of that bootstrap, @p-h-p :-)

@avidality
Copy link

avidality commented Jan 27, 2018

You're basing all your boilerplate and overhead in a procedurally written language. Even the creator of PHP despises the use of frameworks and OOP in general. PHP was made as a simple tool for the C developer to quickly deploy web frontends. Additionally allows novice users and 'webmasters' as you refer to them to publish and share content online through their own servers keeping the internet alive and free. PHP itself is a procedural web framework written in C.

@tsommie
Copy link

tsommie commented Apr 5, 2019

https://github.com/mpphp/mpphp/tree/develop. The goal is to illustrate advanced programming topics using beginners code. Feels like Laravel, but its all Procedural code. Quick setup docs could be found here: https://mpphp.github.io/mpphp/pages/quick-start.html.

@iio7
Copy link

iio7 commented Mar 26, 2021

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

@InFog
Copy link
Author

InFog commented Mar 27, 2021

@iio7 Yes, this is a joke and at the same time it is a reflection on the bloated frameworks we have out there nowadays.

I personally have no problems with procedural code, I actually appreciate it and even use it as a teaching tool https://github.com/InFog/simplestore

@iio7
Copy link

iio7 commented Apr 7, 2021

@InFog, you should change it to a non-joke, a real manifesto, because it's quite good. Remove the part about suppression errors, because that obviously is bad, but then leave the rest.

@InFog
Copy link
Author

InFog commented Apr 7, 2021

I dunno, @iio7. It is too much to be taken serious. I mean, no autoloaders? One file per URL?

I believe procedural code is treated like a joke for no good reason. This manifesto really does not need the error suppression, since one can suppress errors in OO too. But this is still pushing too far on the joke.

@Vuzereus
Copy link

Vuzereus commented Oct 15, 2021

Add:
tldr
Imitate C and C++, make PHP and PHP++, not evolve, but from scratch

https://docs.zendframework.com/zend-servicemanager/reflection-abstract-factory/
When you have things like these just to output some HTML/text/JSON, you will know what bloated means.
The output is less lines than the code.

When the dependency hell comes, you pray and will worship to composer, namespaces and autoload...procedural...rename the function and put in proper module/lib file, done.
For each procedural includes line that OOP despise, can be challenged just by
spl_autoload_register(function ($class_name)
{
file_put_contents('includ.txt', $class_name, FILE_APPEND); // scary stuff happens here
include $class_name . '.php';
}
Granted OOP have advantages and I'm welcome it - https://www.phpclasses.org/, but at 103 base classess, PHP is still procedural.
For me, KISS principle still apply, that just me, I guess.

@InFog
Copy link
Author

InFog commented Oct 18, 2021

@Vuzereus there is no question that framework code can be bloated, it has to handle many user cases.

I believe it is possible to build simpler solutions using no framework at all. Specially for smaller teams.

But then, everything has to be done manually over and over.

Nowadays there are many components that can be used in isolation and can bring advantages outside of a bigger framework.

@tbreuss
Copy link

tbreuss commented Mar 23, 2023

I like this one: https://phpthewrongway.com

@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