1.1 History of PHP
PHP has developed from its origins as a hobby project of Rasmus Lerdorf. Originally started under the name Personal Homepage Tools, it consisted of a series of Perl scripts that Lerdorf used to log access to his website. These scripts then became PHP/FI, which stands for Personal Home Page/Forms Interpreter. Lerdorf implemented this no longer in Perl, but directly in C for performance reasons. PHP/FI had a second version, which was released in November 1997. By this time, however, Andi Gutmans and Zeev Suraski had already been involved in the development. The two were students at the Technion—Israel Institute of Technology at the time and needed a more powerful solution than PHP/FI for a university project. In June 1998, the final version of PHP 3 was released as a coproduction of Gutmans and Suraski with Lerdorf. At this point, the name changed, and development was increasingly transferred to Gutmans and Suraski. Since then, up to the current version (PHP 8), PHP stands for PHP: Hypertext Preprocessor. This is the only correct expansion of PHP; all other variants that you will find in the literature are simply wrong.
1 Introduction to PHP
Lerdorf himself is still very active in the PHP community. After spending several years rushing from lecture to lecture, he worked at Yahoo from 2002 to 2009 and has been working for Etsy since 2012. Gutmans and Suraski founded the Zend company together with Doron Gerstel. The name is made up of the first names of the two main protagonists: Zeev and Andi. PHP has been based on the Zend Engine since version 4. In PHP 5, this engine was version number 2. The Zend Engine was completely revised again with PHP 7. The Zend Engine 3 (formerly phpng) does not introduce as many new functions, but offers a massive increase in performance. However, the history of PHP was not written by just three people. Certainly, these three are closely linked to the success of PHP. But ultimately, it is the large developer community that has made PHP what it is today. The PHP project has had no problem coping with the fact that Lerdorf, Gutmans, and Suraski, for example, are now only minimally involved in development and that the latter two have since left Zend. Microsoft, which previously supported the development of the Windows version of PHP (by seconding developers and taking responsibility for the build system), announced the end of its official PHP support in mid-2020. This was also absorbed by the community; the Windows version of PHP 8 even appeared a few hours before the official release.
_______________________________________________________________________________________________
Note
If you use PHP and have written an extension or something else useful yourself, make it available, whether simply as a PHP class, as a package on Packagist, or even as an official extension. If PHP had not been so strongly supported and so successful, other server-side technologies would surely only be available for money. So by supporting it yourself, you encourage competition and get better products in the long run.
1.2 Success and Commitment
If PHP wasn't so successful, you probably wouldn't be reading this book. Eavesdrop on conversations with friends. From time to time, they say: "I would like to have XY on my homepage." The solution is usually: "Why don't you use PHP?" Or: "I use WordPress, TYPO3, Drupal, Shopware, or some other open-source system. How do I actually extend it?" Here too, the answer is: "Use PHP, that's what the system is written in." What we are trying to say is that PHP has almost become an everyday topic, and as soon as you get to grips with the principles of web programming, you’ll stumble across it.
Let the facts speak for themselves. According to SecuritySpace, almost 50% of all Apache servers have the PHP module installed. The most impressive figures are from W3Techs, where PHP is the market leader among server-side programming languages with 79.1% (see Figure 1.1). Now, statistics are debatable, but it is clear that PHP is the market leader and is used in all segments, from entry-level to high-end systems.

Figure 1.1 Distribution of PHP at W3Techs
The advantages of PHP are obvious: It is already included in smaller hosting packages and is therefore inexpensive. It is also used in the corporate sector by medium-sized companies for websites, store systems, B2B applications, and much more. And PHP is even used on the largest websites. In addition to the famous examples such as Facebook,3 Disney, Lufthansa (with complete ticketing), and Boeing, many other companies rely on PHP. Content management systems based on PHP also prove what PHP can do. These include, for example, well-known open-source projects such as WordPress, TYPO3, and Shopware. And even companies that do not work with PHP on their corporate websites certainly have one or two small PHP solutions internally.
1.3 The Concept of PHP
For all those who have had little to do with the web, the basic model is somewhat unfamiliar. However, once you have internalized it, you will get to grips with it. Let’s play through a case. When you access a website as a surfer, your browser sends a request. This request is made via HTTP. The URL that you specify identifies the web server for which the request is intended. It therefore receives the request and recognizes that you want an HTML file. It sends this file back to you in an HTTP response (see Figure 1.2).

Figure 1.2 Client-Server Model
We will briefly summarize the most important facts from this process: A web server is a program that runs on a server. Browsers and web servers communicate via HTTP. The documents that the web server can pass on are stored on the it. Each document is identified by a URL. Now PHP comes into play. PHP is a server-side technology. This means that PHP runs on the server. In contrast, JavaScript is client-side. JavaScript is interpreted by the browser. This is also why JavaScript sometimes has to be programmed differently for different browsers, whereas with PHP you only have to pay attention to the version used on the server. Let’s now go through the case from earlier again, but this time, you as the surfer call up a PHP page. Let’s start with the request. The URL now contains a file that usually has the .php extension.4 The server sees the file extension and then knows that it must pass the file on to PHP. PHP receives the file and interprets (or more accurately, compiles) it. Interpreting here means that PHP goes through the file (see Figure 1.3). The PHP code is executed within the specially marked PHP areas. The returned result is pure HTML. This is received by the web server, which then sends it back to the browser.

Figure 1.3 Client-Server Model with PHP
Here again are the most important facts:
- PHP is an extension that hooks into the web server.
- The web server passes along all files with certain file extensions (usually .php; formerly also .php4 or .php3).
- When a PHP page is called up, HTML (and possibly CSS and JavaScript) is always sent to the browser at the end, but never PHP code.
This simple principle of a server-side technology applies not only to PHP, but also to other server-side technologies. However, there are often a few special features, such as an intermediate application server or translation into an intermediate language as with .NET.
_______________________________________________________________________________________
Note
One implication of this is that server-side code is very safe from access by brazen thieves. JavaScript, on the other hand, cannot be protected against unauthorized access (even if some protection programs promise otherwise). A password check can therefore only be carried out on the server side.
1.4 The Most Important New Features in PHP 8 to 8.4
The latest version, PHP 8, and its subversions (currently PHP 8.4), is primarily focused on consistency and tidying up. Some practical new language functions also have been added. And, for the first time, there is a very nicely designed page for PHP 8 that shows an overview of all the important new features: https://www.php.net/releases/8.0, this was adopted for later versions p.e. https://www.php.net/releases/8.4.

Figure 1.4 New Features in PHP 8.4
_______________________________________________________________________________________
Tip
If you want to delve deeper into the considerations and decisions of the PHP core developers behind the innovations in PHP 8 and earlier versions, you can find the function proposal RFCs, including the voting results, in the PHP wiki. For PHP 8, see https:// wiki.php.net/rfc#php_80; for PHP 8.4, see https://wiki.php.net/rfc#php_84.
The following list provides an overview of the most important new features of PHP 8:
- PHP now includes a just-in-time (JIT) compiler. PHP is actually an interpreted programming language; that is, it is executed when called and is not converted into machine code before execution like a compiled programming language. The JIT compiler is a kind of middle ground. It is used to precompile code where appropriate and works closely with the code-caching system in PHP 8. In many applications, the reward for the effort is increased performance without functional disadvantages.
- The completely new match language construct is introduced as an often-simpler alternative to the switch case distinction. More on this in Chapter 5.
- Named parameters allow access to function and method parameters, regardless of the order. You can read more about this in Chapter 6.
- Union types extend the typing by the possibility of defining several types for method parameters or their return. You can also read more about this in Chapter 6.
- The new mixed type that stands as a representative for any type. Admittedly, this is also the default behavior if you omit the typing—but with mixed you specify this
behavior directly, and even with strict typing you will not get a type error.
Internal typing has also been tidied up in PHP 8, and many core functions have been revised: - PHP-internal functions now also consistently return TypeError errors in the event of incorrect typing.
- The ?-> nullsafe operator considerably simplifies the null check for nested objects.
- For comparison and bitwise operators, the comparisons between string and number have been revised.
- PHP 8 allows commas at the end of parameter lists as a small syntactic addition. There have also been some interesting innovations in object orientation (see Chapter 11):
- static is now also permitted as a type for the return of methods.
- The newly introduced property promotion for the constructor of a class saves a lot of unnecessary typing when creating properties in the constructor.
- With so-called attributes, PHP 8 introduces native metadata that you can also access at runtime via the Reflection API. This is a native alternative to other annotation options such as PHPDoc.
- In PHP 8, the inheritance of private methods with the same name is no longer "unnecessarily" checked.
- WeakMap is a new standard class for the "weak" references introduced in PHP 7.4.
- PHP 8 automatically adds the new Stringable interface to classes that use __ toString().
- The trend in error handling has also been toward cleanliness: the @ operator no longer suppresses fatal errors. Many inconsistencies in error handling have been eliminated, including illogical warning levels (https://wiki.php.net/rfc/engine_warnings). try-catch is now also possible in the catch block without a variable definition.
- In string handling, the three str_contains(), str_starts_with(), and str_ends_with() functions have been added. (See also Chapter 7.)
- The create_function() and each()methods in the array-handling area have been removed.
- For many extensions, such as the GD graphics library or the XML parser, PHP worked internally with so-called resources. These resources were largely converted into objects in PHP 8. And wherever there are still resources, get_resource_id() enables conversion to an integer value.
And this is an overview of important functions that are new in PHP 8.x up to 8.4: - As of version 8.1, PHP allows a new octal notation for numbers with 0 in front and an o behind.
- Since PHP 8.1, PHP allows enumerations with fixed data values. More on this in Chapter 6.
- New in PHP 8.1 is the never keyword as a return type for functions. Since PHP 8.2, null, false, and true are also possible as types, and DNF types allow mixed returns. More on these topics in Chapter 6.
- Since PHP 8.2, there is a new, significantly better Random\Randomizer class for mathematical functions, which can be found in Chapter 9.
- PHP 8.4 brings new array_*() functions.
- In PHP 8.4 the DOM API was completely refactored. This includes standards-compliant support for the parsing of HTML5 documents.
There are now some new functions in object-oriented programming, which have been constantly optimized: - In PHP 8.1, the option to declare properties as readonly was added. In PHP 8.2, readonly was then also possible at the class level.
- As of PHP 8.1, objects can also be used as static variables, as default values for parameters, and as global constants and parameters for properties.
- In PHP 8.1, dynamically set properties are classified as deprecated. Instead, they can be specifically allowed for a class by setting the attribute named #[AllowDynamicProperties].
- Since PHP 8.1, constants in classes can also be marked as final.
- As of PHP 8.3, constants can also be typed with data types.
- In PHP 8.3, the #[\Override] attribute allows you to mark a method that, as the name suggests, overrides another.
- In PHP 8.1, fibers are added as a new concept. They allow the execution of parallel calls in PHP and are therefore an approach for multithreading. More on this can be found in Chapter 26.
- Since PHP 8.3, the json_validate() method allows JSON strings to be validated before decoding
- PHP 8.4 supports property hooks. They provide support for properties that can natively be read by IDEs and analysis tools, without the need to write DocBlock comments that might go out of sync.
- PHP 8.4 supports asymmetric visibility, that means a property can have different types of visibility, for instance public for reading and private für setting.
- With the #[\Deprecated] attribute in PHP 8.4 you can use the deprecated functionality for own methods, constants and functions.
1.5 The Most Important Features in PHP 7.3
As with previous versions, PHP 7.3 does not contain any groundbreaking changes compared to the previous 7 versions. However, some incompatibilities should be noted, and some new functions may be helpful:
- From PHP 7.0 to 7.1, the handling of "empty" returns for functions has been changed. If the return value is typed with a ? in front of the data type, then a return of zero is also possible. However, if the return value is specified as void, returns with zero are not permitted.
- nce PHP 7.1, the array abbreviation with [] can also be used as a basis in foreach, for example. This variant still exists alongside list(). Also since PHP 7.1, both the shorthand notation and list() allow the use of named indices. Since PHP 7.3, both also allow references with &.
- Heredoc and nowdoc have been somewhat simplified in PHP 7.3, in that it is no longer absolutely necessary for the closing to be done with a line break and without indentation.
- Since PHP 7.2, extensions can be called in php.ini without a file extension (.so for Unix or .dll in Windows).
- Some adjustments have also been made to object orientation:
– In PHP 7.1, the iterable pseudotype was added for a method parameter, which indicates that the object that is passed is iterable—that is, has implemented the Traversable interface.
– The instanceof operator allows literals as the first operand with the result false. – Since PHP 7.1, it has also been possible to define the visibility of constants using the keywords public, protected, and private.
– Since PHP 7.2, there is a new object type for function parameters.
– Since PHP 7.2, the handling of numeric indices when converting arrays into objects has changed.
– With the new static fromCallable() method of the Closure class, methods can be converted into Closure objects since PHP 7.1.
– Since PHP 7.2, abstract methods can be overridden in inheriting abstract classes.
– Since PHP 7.2, parameter types can be omitted from overridden methods.
– In PHP 7.2, there is now a syntax for namespace groups followed by a comma. - In exception handling, PHP 7.1 already added the option of catching multiple exceptions separated by the pipe character (|) in a catch block.
- Another aspect of error handling is that since PHP 7.1, many extensions increasingly throw error exceptions instead of the less manageable fatal errors. There is a long list to mention here: Date, DBA, IMAPG, Intl, LDAP, Mcrypt, MySQLi, Reflection, Session, SimpleXML, SPL, Tidy, WDDX, XML-RPC, and ZIP. This trend was also maintained in the next versions; for example, the new error handling was added to BCMath in PHP 7.3.
- Since PHP 7.1, negative offsets are also possible in string handling when accessing characters of a string with [] or with strpos().
- In the security area, in PHP 7.2, the Sodium cryptography extension became part of the core. Argon2 for password hashes was also added. In PHP 7.3, Argon2id support for password generation was implemented.
- The LDAP functions have been continuously expanded, including with new parameters and extended operations (EXOP).
- The mbstring functions have been slightly expanded in PHP 7.3 and optimized in terms of performance. The most exciting functional innovation is complete case mapping, in which, for example, a sharp S (ß) is also taken into account. In PHP 7.1, the error handling of some functions for regular expressions has been improved.
- As usual, further functional areas and libraries have been continuously developed— for example, cURL, EXIF, Readline, SQLite3, PCRE, and ZIP.
1.6 The Most Important Features in PHP 7
PHP 7 sounds like a big leap in terms of new features. In fact, the jump was not too extensive in terms of functionality, but the base engine was changed:
- Speed
The most important goal behind the complete redevelopment of the PHP core was to increase performance. The model here was the customized PHP implementation used by Facebook. - The old and the tidy
- The short tags in ASP notation are no longer available; there is no longer a setting
for asp_tags in php.ini.
– The integration of PHP code with
1.7 The Most Important Features in PHP 5.4, 5.5, and 5.6
The new features in PHP 5.6 are not too extensive. For this reason, we have also listed the most important new features in PHP 5.4 and 5.5 compared to 5.3:
- There have been various innovations in object orientation:
– In PHP 5.4, traits were added that allow the reuse of code in generally defined methods.
– With PHP 5.4, properties and methods can be accessed directly in the instantiation of an object.
– In PHP 5.5, you can read class names including namespaces with ::class.
– In PHP 5.6, you can use the use keyword to import constants and the like into classes. - There are also multiple language changes:
- In PHP 5.4, there were some new features for arrays. Among other things, a short syntax based on JSON was defined.
– PHP 5.4 defines its own binary format for numbers.
– In PHP 5.5, generators with the yield keyword were added to easily iterate through elements.
– As of PHP 5.5, foreach together with list() is allowed.
– As of PHP 5.6, the ... operator can be used to catch excess parameters of a function or method.
– As of PHP 5.6, the same operator can be used to pass an array with parameters to a function.
– The ** operator allows exponential calculation as of PHP 5.6. - In PHP 5.4,
- PHP 5.4 comes with a development web server in CLI mode.
- PHP 5.6 now allows file uploads of more than two gigabytes.
- A few things have also changed in the extensions:
– In PHP 5.4, sessions can also track the upload progress of files.
– In PHP 5.5, the GD extension was supplemented with cropping functions, among other things.
– The OPcache extension for the Zend opcode cache was added in PHP 5.5.
– SSL/TLS support has been improved in PHP 5.6.
– In PHP 5.6, the pgsql extension was extended to include asynchronous connections. - Some functions have also been declared obsolete again. These include the old MySQL extension ext/mysql, which is deprecated as of PHP 5.5. In PHP 5.6, the encoding information of the iconv and mbstring functions has also been deprecated because default_charset is now the official main way to determine the character set.
________________________________________________________________________________________
Note The appendix to the PHP documentation (see http://php.net/manual/appendices.php) provides a good overview of all the new features.
1.8 Downloads and Documentation
You can learn how to install PHP in Chapter 2. The official place to get PHP, and to find the extensive online documentation, is www.php.net. Hardly any other open-source project can boast such a good website. And even some commercial products could take a leaf out of its book.
___________________________________________________________________________________________
|
Note the changelog for new versions, which lists important changes to the previous version. You should always run as up-to-date a version as possible on your server, as security holes may also be plugged. However, test in advance whether your scripts run smoothly with the new version. PHP is usually downward compatible, but usually is unfortunately not the same as always. If your script runs on a hosting package, you are of course bound to the version used by your host. This should then also run on your workstation. |
Comments
0 comment