Published

PHP’s new and improved version, PHP 8.2, was released on November 24, 2022. Are the newly added improvements significant, and do I need to upgrade my version as soon as possible? Or maybe I would better wait a while? Why is PHP still so popular, and what are its pros and cons? We will try to provide you with all these answers in this text. We hope you enjoy it!

What is PHP?

PHP is the short form for “Hypertext PreProcessor” (previously for “Personal Home Page). It is still the most reliable and easy-to-learn scripting language in the field of developing dynamic websites and web apps. Initially released by the Danish-Canadian programmer Rasmus Lerdorf in 1995, PHP was used by 74.4% of all server-side websites in October 2022. PHP’s code is embedded in the HTML pages, and its syntax and those of Java and C are quite alike.

Who is Using PHP?

Even though many new script languages are appearing nowadays, PHP is still the most popular one. It is widely used among websites based on content management systems, such as WordPress, Joomla, Moodle, and many others.

Some of the most popular websites around the globe are built upon PHP. Here is just a small list of examples:

  • Facebook
  • Yahoo
  • Spotify
  • Wikipedia
  • Slack
  • Tumblr
  • Pfizer
  • Flickr
  • 9GAG
  • WhatsApp
  • 360.cn
  • VK
  • Zoom
  • Daily Mail
  • CCTV

Who Created PHP?

Born on a frosty Greenland island, PHP’s founder Rasmus Lerdorf spent much of his childhood in Denmark and moved with his family to Ontario, Canada in his teenage years. He is known for being extremely modest about his programming creation, even comparing it with a toothbrush.

Once Lerdorf said about PHP:

”You use it every day, it does the job, it is a simple tool, so what? Who would want to read about toothbrushes?”

PHP’s Advantages & Disadvantages

Just like any other similar script language, PHP also has a variety of pros and cons. Here is a list of the main ones that you should consider before choosing PHP for your shiny website or innovative web application.

Advantages

  • Accessible to all: PHP’s most essential advantage is probably the fact that it is open-source. People can get it throughout the internet and use it for the development of each website or app.
  • Easy-to-learn: As we already mentioned above, PHP is quite an easy-to-learn language, probably just a little bit more difficult than HTML. It doesn’t require long-drawn codes to function properly.
  • Easy combination with other languages: Not only is PHP quite easy to learn and use, but it is also ready to combine with many other code languages in HTML.
  • It is for free: You can download it from the Internet for completely free and gladly use it.
  • Goes well with low-speed internet: One of the primary reasons why people prefer PHP to other similar script languages is that it lets sites and apps load even when the internet speed is sluggish. That’s why PHP is especially preferred for websites designed for regions with compromised internet connections.
  • Available on all operation systems: No matter if Linux, Windows, or iOS. Anyone can access PHP-based websites, no matter what the OS of their desktop or mobile device is.
  • It is well-supported: With PHP you don’t need to worry if you have the latest version. Unlike other script languages, PHP’s versions are privileged with long-term support.
  • Great database connection: PHP’s database connection makes developing PHP-based websites and applications fast and hassle-free.
  • Good library support: PHP has a set of pre-coded stuff that developers could enjoy. They could use them to make the most effective problem-solving.
  • Provides job opportunities: In the world of programming, it has been nearly a must to be familiar with PHP to get a job in the last 25 years. Learning PHP will open many doors for you, especially in the current situation when the number of PHP specialists is decreasing. Therefore, the prices of PHP-related services will most probably start running up in the upcoming years.

Disadvantages

  • Many competitors: Though PHP is an easy script language, and it is still dominating, there are many other similar languages, such as Python and Ruby, that are gradually displacing its uniqueness due to better performance in giant web apps.
  • Relatively weaker overall performance: The usage of several PHP tools at once could lead to poor performance of the website. Unlike PHP, many newer scripting languages are significantly better enhanced in it.
  • Suitable for lightweight apps mostly: PHP might not be the right choice if your desire is to create a very huge application. However, it is a wonderful and inexpensive solution for small and medium applications.
  • Weak frameworks: PHP frameworks aren’t the best. They are not honored for requiring many mutually dependent classes, for providing the developer with complex solutions, and for other issues that make web development more labor-intensive.
  • Less debugging options: Compared to other newer programming languages, PHP has a smaller set of debugging tools. As PHP is prone to errors, in some cases it might be a huge con.
  • Plain text files are not private: Even though in most cases it is not a huge drawback, you should consider that anyone could access the plain text of your website. This omission could make your website prone to malicious activities such as manipulations and attacks by hackers.

PHP 8.0: The Last Big Modification

The last major update of PHP, the 8th one, significantly differs from the previous 7th versions. Officially released in November 2020, PHP 8.0 involves various amendments, including the following:

  • Just-in-time (JIT) compilation: An element that improves the performance of web pages and apps by gathering bytecodes to native machine code.
  • Match expression: An expression similar to the “switch” statement but more useful in some cases.
  • Throw expression: Previously a statement, “throw” was changed to be an expression.
  • Syntax changes: Changes that allow alternative, shorter, and more consistent syntaxes in a number of scenarios.
  • WeakMaps: They improve performance when data is being cached.
  • New functions: Many interesting new functions, such as fdiv(); get_debug_type(); and get_resource_id().

PHP 8.1: Slightly Improved Version of 8.0

11 years ago, In 2011, the development team of PHP announced that they will be launching a minor new version each year.

PHP 8.0’s last subversion, the 8.1 one, was released a year later, in November 2021. It included some minor improvements, such as the following, making work with PHP just a little bit easier for the developers:

  • Enums (a shorter form of “enumerations”): An instrument that allows enforcing states in a codebase.
  • Improvement of read-only properties: Added support for ‘readonly’ properties.
  • Improvement of array unpacking with string keys: Added support for array unpacking with string keys.
  • New return type: The return type “Never” was added.

PHP 8.2’s Top 8 Improvements Revealed

This year’s annual update of PHP is the 8.2 version. It is expected to be released on the 24th of November. Though it will be a minor modification of the 8.0 and 8.1 versions, it consists of improvements that could significantly polish the developer’s experience in specific cases.

Improvement #1: New Disjunctive Normal Form (DNF) types

DNF is a way to organize expressions of binary variables with two possible values – “true” and “false” – precisely into an ORed series of ANDs. Once applied to type declarations, DNF activates a way to write combined Union and Intersection types.

It’s considered to be a significant change as developers would be able to write “nullable” intersection types:

function getFullName ( (HasName&HasSurname) |null $user) { . . .}

Improvement #2: Declaring the entire class as ‘Readonly’

PHP introduced the read-only properties last year in their PHP 8.1 version. With PHP 8.2, a new feature will be launched: an opportunity to declare a whole class as read-only (‘readonly’).

class readonly MyClass
{
public string $bookName,
public int $count,
public string $authorName,
public int $price
}

By declaring the entire class as read-only, all the rows will automatically turn into ‘readonly” too.

Improvement #3: Defining constants in traits

Resembling classes, traits are applicable for grouping methods in a refined and successive way. Developers will be able to define constants with this new improvement in PHP 8.2.

trait Foo
{
  public const CONSTANT = 1;
 public function bar (): int
{
            return self : : CONSTANT;
}
}

Improvement #4: Enum properties in constant expressions

Developers would enjoy another useful improvement included in the 8.2 version of PHP.

Fetching properties of enums in constant expressions will be possible by simply using ->/?->. The main factor for the change is allowing fetching the name and value properties in array keys. In the 8.0 and 8.1 versions, this is still not allowed.

enum A: string
{
  case B = “B”;
          const C = [self : : B ->value => self : :B];
}

Improvement #5: Editing sensitive parameters in backtraces

Backtraces are a great feature, but sometimes they might be detrimental to personal data.

As with most programming languages, anything in the execution of the code can be traced in PHP too. Errors related to production are usually sent to third parties which let the developer know if something goes amiss. But the backtraces sometimes include sensitive data, such as usernames and passwords.

To resolve this potential issue, PHP 8.2 provides an instrument to mark all the sensitive parameters with an attribute called “SensitiveParameter”.

function passwordHarsh (#[\SensitiveParameter] string $password) {
     var_dump (debug_backtrace( ) );
}
passwordHash (‘hunter2’);

Improvement #6: New functions

PHP 8.2 includes several new functions that could improve any PHP developer’s overall performance. They all create favorable conditions for shortcuts saving time and effort.

Mysqli_execute_query

PHP 8.2’s MySQLi extension covers a new mysqli_execute_query function and execute_query method. With them, developers could work up, strap, perform, and get back results from a Structured Query Language (SQL).

$query = ‘SELECT uid, username FROM users WHERE uid = ? ’ ;
$result = $mysqli->execute_query($sql, [$uid] ) ;

Ini_parse_quantity

Ini_parse_quantity is a newly created function available in PHP 8.2. It can be used in parsing INI values in an app.

Ini_parse_quantity has the ability to parse any size of data (for instance 56K) recognized by PHP INI values. As a result, the function returns the size of the data in bytes.

function ini_parse_quantity(string $shorthand): int {
}

Memory_reset_peak_usage

Another new function in PHP 8.2 is memory_reset_peak_usage. It was made for easier resetting the maximum memory usage reversed by another function that is already existing: memory_get_peak_usage. With the latest PHP version, any app that repeats an action many times could get its tracking peak memory improved.

function memory_reset_peak_usage(): void {
}

Curl_upkeep

PHP 8.2’s Curl extension has a new function too: curl-upkeep. It was developed to keep a Curl connection operating, but it doesn’t back connection upkeep for all connection types. Currently, connection upkeep is existing for HTTP/2 connections only.

function curl_upkeep(CurlHandle $handle) : bool {
}

Improvement #7: Improving the curl_getinfo function

Information about a specific Curl transfer is restored by the curl-getinfo function. PHP 8.2’s developers have added a tool to retrieve the effective method of a request.

If we don’t clarify any parameter in the curl_getinfo function, we will get all the information about the Curl transfer. In PHP 8.2 there is an additional instrument called effective_method, containing the name of the HTTP request’s effective method.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://example.com');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
$info = curl_getinfo($ch);
var_dump($info);

Improvement #8: Avoiding the deprecation notice for dynamic properties

PHP 8.2 expands its usability with a new attribute named AllowDynamicProperties. It helps in avoiding deprecation notice for dynamic properties.

Once any class is stated with the attribute #[AllowDynamicProperties], it stops emitting dynamic property deprecation notices.

#[AllowDynamicProperties]
class User () {}
$[AllowDynamicProperties]
class User () {}
$user = new User ();
$user ->foo = ‘bar’;

Detailed Information About PHP 8.2

In case you need a more comprehensive tutorial about the new PHP 8.2 features, we would kindly recommend you watch this video. In it, a web developer gives a very detailed and practical explanation of the new PHP version to be released.

Please accept cookies statistics, marketing to see this content

Are PHP 8.2 and WordPress compatible with each other?

If your website is based on WordPress, you are probably well aware of the importance of keeping WordPress up-to-date. It is no less substantial to keep your PHP’s versions updated too.

As some WordPress add-ons might not be completely compatible with the latest PHP’s version yet, it won’t be bad to do these actions warily. It wouldn’t hurt to have updating your PHP on your to-do list, but sometimes it might be better not to rush.

Wondering when would be the right time for your version to be updated to PHP 8.2? Don’t hesitate to ask Seravo’s incredibly well-skilled and very kind experts. Regardless of the plan you choose, they can take care of the overall upkeep of your hosting and WordPress. You could contact them anytime you have any questions or issues to solve with your website’s support.

Read more

In category: Development

PHP 8.3 Available at Seravo

PHP 8.3 is now available on WordPress sites hosted at Seravo.

February 22, 2024

DKIM, SPF and DMARC: Ensure Email Delivery with DNS Records

Trouble getting your emails delivered? Check out your domain’s DNS records to ensure your messages are not flagged as spam.

February 20, 2024

PHP 8.3 Released Today

PHP 8.3 has been released. Here’s what’s new and how to keep your PHP version up to date!

November 23, 2023

WP-CLI v2.8.0 Released

After a small delay, a new version of the WP-CLI command line tool was finally released yesterday, May 31st, 2023. […]

June 1, 2023

PHP 8.2 Soon Available

PHP 8.2 becomes available at Seravo for developer testing. However, we recommend using PHP8 on your live WordPress site – for now!

February 3, 2023

Upcoming PHP Updates at Seravo

Since 2022 PHP 8.0 has been the default PHP version at Seravo, and is automatically enabled on all new sites. PHP 8.1 is also available, and PHP 8.2 will be soon available for developers!

January 25, 2023