Need urgent help with your website?Describe your issue and we will respond as quickly as possible.

The History of PHP: From Its Creation to the Current Version 8.3

—

by

in

PHP is one of the most popular programming languages for web development. Since its creation in 1994, it has come a long way, evolving from a simple tool for dynamic web pages into a powerful, high-performance, and versatile programming language. Let us look at the main stages of its development and discuss in detail the key changes in versions 8.0, 8.1, 8.2, and 8.3.


Stages of PHP Development

1995: The Birth of PHP/FI 1.0

PHP was created by Danish programmer Rasmus Lerdorf in 1994 as a set of Perl scripts to track visits to his résumé on a website. In 1995, he released the first version of PHP/FI (Personal Home Page/Forms Interpreter), supporting HTML forms and database interaction.

1998: PHP 3.0 and a Revolution in the Language

With the help of Zeev Suraski and Andi Gutmans, PHP was completely rewritten, leading to the release of PHP 3.0 in 1998. It introduced the new Zend Engine, which significantly improved the language’s performance and flexibility. PHP 3 became the first widely used version of the language to support object-oriented programming.

2000: PHP 4.0 and the Introduction of Zend Engine

PHP 4 with Zend Engine 1.0 was released in 2000, offering improved performance and session support, making PHP better suited for building complex dynamic web applications.

2004: PHP 5.0 and a New Era of OOP

PHP 5, released in 2004, introduced full support for object-oriented programming, improved database interaction through PDO (PHP Data Objects), and a new exception handling model.

2015: PHP 7.0 and Significant Performance Improvements

In 2015, PHP 7.0 introduced the next-generation Zend Engine 3.0, doubling code execution speed and adding support for typing function arguments and return values.


PHP 8: Key Innovations

PHP 8.0, released in November 2020, was an important step forward thanks to many new features and improvements that made the language more convenient, performant, and expressive. The key innovations include:

1. JIT Compilation (Just-in-Time)

The JIT compiler makes it possible to dynamically compile part of the bytecode into machine code at runtime. This is particularly useful for computationally intensive tasks, such as scientific computing or machine learning. However, JIT has less impact on typical web applications.

Example:

<?php
function fibonacci($n) {
    if ($n == 0) return 0;
    if ($n == 1) return 1;
    return fibonacci($n-1) + fibonacci($n-2);
}

echo fibonacci(30);
?>

2. Match Expression (Pattern Matching)

match is an improved version of the switch statement that uses strict typing, does not require break statements, and can return a result directly.

An example of using match:

<?php
$status = 404;

$message = match ($status) {
    200 => 'OK',
    404 => 'Not Found',
    500 => 'Internal Server Error',
    default => 'Unknown Status',
};

echo $message;  // Выведет: Not Found
?>

3. Named Arguments

Named arguments make it possible to pass function parameters by name, making function calls clearer and more convenient.

Example:

<?php
function greet(string $name, string $greeting = 'Hello') {
    echo "$greeting, $name!";
}

greet(name: 'John', greeting: 'Welcome');  // Выведет: Welcome, John!
?>

4. Union Types

Union types allow you to specify multiple types for arguments and return values.

Example:

<?php
function processInput(int|string $input) {
    if (is_int($input)) {
        return $input * 2;
    } else {
        return strtoupper($input);
    }
}

echo processInput(10);  // Выведет: 20
echo processInput('hello');  // Выведет: HELLO
?>

5. Constructor Property Promotion

This feature makes it possible to automatically assign object properties from constructor arguments, reducing the amount of code.

Example:

<?php
class Point {
    public function __construct(
        public int $x,
        public int $y
    ) {}
}

$point = new Point(3, 5);
echo $point->x;  // Выведет: 3
?>

6. Errors for Invalid References

PHP 8 generates errors when accessing non-existent array keys or object properties, improving code reliability.

Example:

<?php
$data = [];
echo $data['key'];  // Fatal Error: Uncaught Error: Undefined array key "key"
?>

PHP 8.1: Important Innovations

PHP 8.1, released in November 2021, added many important features and improvements, such as enums, fibers, and readonly properties.

1. Enums

Enums (enum) make it possible to define a fixed set of values used in code.

Example:

<?php
enum Status {
    case Pending;
    case Completed;
    case Failed;
}

function handleStatus(Status $status) {
    return match ($status) {
        Status::Pending => 'Pending',
        Status::Completed => 'Completed',
        Status::Failed => 'Failed',
    };
}

echo handleStatus(Status::Pending);  // Выведет: Pending
?>

2. Fibers

Fibers add the ability to create cooperative threads in PHP, simplifying asynchronous programming.

Example:

<?php
$fiber = new Fiber(function() {
    $value = Fiber::suspend('fiber suspended');
    echo "Resumed: $value\n";
});

echo $fiber->start();  // Выведет: fiber suspended
$fiber->resume('resume value');  // Выведет: Resumed: resume value
?>

3. Readonly Properties

readonly properties can be initialized only when an object is created, after which they become immutable.

Example:

<?php
class User {
    public readonly string $name;

    public function __construct(string $name) {
        $this->name = $name;
    }
}

$user = new User('Alice');
// $user->name = 'Bob';  // Ошибка, так как свойство readonly
?>

PHP 8.2: Continued Improvements

PHP 8.2, released in December 2022, brought further syntax improvements and new features.

1. Readonly Classes

PHP 8.2 allows classes to be declared as readonly, which automatically makes all their properties immutable.

Example:

<?php
readonly class Product {
    public function __construct(
        public string $name,
        public float $price
    ) {}
}

$product = new Product('Laptop', 1200.00);
// $product->price = 1300.00;  // Ошибка, так как класс readonly
?>

2. Deprecation of Dynamic Properties

Dynamic properties created outside a class declaration are now deprecated, which helps prevent errors.

Example:

<?php
class User {}

$user = new User();
$user->name = 'John';  // Deprecated: dynamic properties are deprecated
?>

3. Support for null, false, and true in Union Types

You can now specify null, false, and true as types in union types.

Example:

<?php
function test(null|false|string $value): string {
    return $value === null ? 'null' : ($value === false ? 'false' : $value);
}

echo test(null);    // Выведет: null
echo test(false);   // Выведет: false
echo test('test');  // Выведет: test
?>

PHP 8.3: Latest Improvements

PHP 8.3, released in November 2023, continued to improve the language with a focus on enhancing security and adding new useful features.

1. json_validate

A new json_validate function has been added, allowing you to check whether a JSON string is valid without decoding it.

Example:

<?php
$json = '{"name": "John", "age": 30}';
$is_valid = json_validate($json);
echo $is_valid ? 'Valid JSON' : 'Invalid JSON';
?>

2. Typed Class Constants

You can now declare types for constants within classes, strengthening type safety.

Example:

<?php
class Config {
    public const string NAME = 'Application';
}

echo Config::NAME;  // Выведет: Application
?>

Conclusion

PHP 8.0 and later versions have brought many improvements that significantly enhanced the language’s performance and expressiveness. From JIT compilation and innovations such as match, union types, and fibers to the latest improvements in PHP 8.3, the language continues to evolve and adapt to the requirements of modern web applications, remaining a key tool for millions of developers around the world.

I have great news for all my subscribers! 🎉 When paying for JetBrains products, you can use the special promo code “Asgru24” and get a 25% discount on any product! Don’t miss the opportunity to save on the best development tools.


👍
❤️
😂
😮
😢
😡
🤔
👏
🔥
🥳
😎
👎
🎉
🤯
🚀
₿
Ξ
Ł
Ð
🌕