As you probably already know, PHP is one of the best-known server-side programming language used in web applications. Known by a lot of web developers, it has been appreciated for being intuitive and easy to learn, but also often criticised for some peculiar features incorporated in the design. The creator of PHP is Rasmus Lerdorf, who was invited to deliver a speech during Codemotion Rome 2019, on the 25th anniversary of the first PHP release.
In this article, we will summarise the origins of PHP and some curious facts about it, inspired by Lerdorf’s stories and facts discussed during his talk.
In order to understand why and how PHP originated in Lerdorf’s mind, it is useful to provide a bit of an overview of the context in which it was born. In the early ‘90s, the Internet was very different from now. Browsers had very limited options and developers had much fewer options than now to implement web servers. Just to give you an example, the following snippet (shown by Lerdorf during his talk) is an example of how a basic web server was written using C in 1993:
As you can see, building a page required writing low level code and to output both content and headers line by line. Moreover, using C produced long code snippets for doing something quite simple, eg. returning a web page as a response of a HTTP request. There were other programming languages more compact and still powerful (as shown by the Perl snippet below) but such solutions still did not solve a basic problem: the possibility of separating content presentation from the other server business logic (particularly request and response processing).
To solve the problem of content separation, Lerdorf decided to develop PHP, releasing its first version in 1995. His idea was clear: using it as a templating language, where you can embed little snippets just to show outputs of functions or values saved in variables, while the rest of the server-side business logic could continue to be implemented in separated CGI.
For more clarity, the following snippets represent what Lerdorf expected to be the common use of PHP. Basically, the idea was to have a C API for web, allowing us to do something like this:
And then, PHP served as a templating language, embedding functions or variables defined in C directly in the middle of HTML:
You might think that this is quite different from what we usually do with PHP. Indeed, today PHP has the form of a fully-working programming language, with no need of using C API. The original goal of separating presentation from server business logic is often misunderstood, or ignored. Lerdorf explained that his initial idea has been rejected by most people, although he often tried to explain his original position. He finally surrendered to this in 1999, when PHP was already supported (and used) from a plethora of ISP.
After its official release, PHP has become the popular language we know. But this was also due to many other things built all around it. Probably the most important innovation due to PHP is represented by the LAMP stack, which originally meant Linux, Apache, mSQL and PHP, since MySQL was not yet ready. mSQL was a very simple RDBMS, which was included in the original idea exactly for its simplicity, but then replaced when servers required more advanced features.
Today, PHP is widely used in many websites and applications, such as Wikipedia and WordPress, to name but a few.
Before ending with this article, it is worth mentioning a couple of interesting facts and remarks told by Lerdorf during his talk.
First, he mentioned some problems often considered bad design choices of PHP. He started discussing the choice of using case insensitive function names, explaining it with the original idea of content separation Since they needed to be included in a templating language like HTML (which is case insensitive), he designed the API (and thus the resulting language) for being case insensitive in function names.
Another issue analysed was the naming inconsistencies, which Lerdorf explained as simply due to the different conventions in the context where PHP was developed. More generally, most of these issues may indeed been explained by the context where PHP was developed, at the beginning of the Internet and with many things evolving quickly.
Finally, Lerdorf highlighted the importance of working on things that matter and always have a sense of purpose in our everyday life. He says he does not consider himself as a good programmer, but instead a dreamer. And his dreams have become true not just because of his programming skills, but instead because of his sense of purpose, his desire of trying and making new things. We often focus on being great developers, learning every single feature of our preferred programming language. Perhaps working on our goals is the key to drive us to new challenges, discover new passions and thus – maybe – developing another (better) PHP.
Read more about PHP here