The cart is empty

The development of the PHP language continues steadily, and with each new version comes not only new features but also the removal of older, outdated, or unsafe elements. PHP 8.4, released in November 2023, brought several changes that deserve the attention of developers. In this article, we will look at the specific functions that were removed in this version and recommendations on how to deal with these changes.

1. Removed Functions and Constants

1.1 Deprecated Functions

PHP 8.4 completely removed some functions that had previously been marked as deprecated. This decision is in line with the policy of gradually phasing out old elements to maintain code cleanliness and security. Among the removed functions are:

  • each(): This function was widely used in earlier versions of PHP to iterate over an array. It has been replaced by more modern and safer constructs, such as foreach loops.

  • get_magic_quotes_gpc() and get_magic_quotes_runtime(): These functions were part of the magic quotes mechanism, which was criticized for its security flaws and had been deprecated earlier.

1.2 Deprecated Extensions

PHP 8.4 continues the phasing out of deprecated extensions that are no longer considered safe or have been replaced by better alternatives. For example:

  • ext/ereg: This extension for regular expressions was completely removed and replaced by the PCRE (Perl Compatible Regular Expressions) extension, which is faster and more secure.

  • ext/mcrypt: This encryption extension was removed due to outdated functions, and better alternatives now include ext/sodium or ext/openssl.

2. Implications for Developers

The removal of these functions and extensions has a direct impact on developers who need to update their older code to be compatible with the new version of PHP. Here are a few steps developers should take:

  • Code Review: Scan existing code to identify the use of deprecated functions. Tools like PHPStan or Phan can help automatically identify problematic areas.

  • Replacing Functions: Deprecated functions should be replaced with their more modern equivalents. For example, instead of each(), a foreach loop should be used.

  • Testing: After making adjustments, it is crucial to conduct thorough testing to ensure that the new code works correctly and does not contain errors caused by the changes.

 

PHP 8.4 brings many benefits and improvements but also requires developers to be proactive in maintaining and updating their applications. The removal of deprecated functions is an important step towards a more modern, secure, and efficient code. Developers should take these changes as an opportunity to improve their applications and further develop their skills in working with PHP.