PHP: no, its not possible
Jul 19, 2024 pm 02:14 PMYou may add "yet" to this title! Sometimes, things are what they are simply because nobody knows how to do better.
However, it does not mean everything is a good idea.
PHP doesn't support multiple inheritance
You simply cannot do the following:
class Child extends Parent1, Parent2 {}
However, many developers would think there are better approaches, like using interfaces to force classes to implement specific behaviors.
Note that you may still apply some kinda of multiple inheritance to those interfaces (if that really makes sense in your case):
interface A {} interface B {} interface C extends A, B {}
However, that's not the best argument against multiple inheritance, to me. Many programming languages focus on simplicity and readability over complexity.
Introducing multiple inheritance could lead to lots of misuses, not to mention the Diamonds problem, which would be problematic for high-level languages such as PHP.
It's best if you can avoid unnecessary complexity.
PHP does not support multi-threading
Many programming languages provide built-in tools to execute multiple threads at the same time (e.g., Java, C++).
Pthreads tried to introduce multi-threading in PHP but Joe Watkins the creator of pthreads and parallel announced in February 2019 that:
pthreads will no longer be maintained after PHP 7.4 due to architectural flaws.
Source: PHP documentation - phtreads
If you want to dig further, you may check parallel, which is inspired by Go concurrency.
While parallel is pretty cool, do you really need such complexity in your case?
If you need a built-in mechanism for asynchronous processing, it is now possible with Fibers (since PHP 8.1).
Fibers allow you to write interruptible functions.
While Fibers are pretty cool, do you really need such complexity in your case?
Using third-party solutions such as ReactPHP or Swoole could be a better choice, especially if you only need an event loop.
Better than that, you may build a queue mechanism that can handle messages and retry failed jobs.
The Symfony component HTTP Client also supports various asynchronous operations (e.g., concurrent asynchronous streamed and multiplexed requests/responses).
PHP is not meant for real-time processing
PHP is an interpreted language, which is incompatible with intensive operations and systems that require low latency and high predictability.
While is true, why would you use PHP for High-Frequency Trading, streaming, online gaming or high-level supervision of machines and processes?
Wrap up
PHP is meant for the web and many other creative uses you may know.
I hope it will keep its simplicity, as it is definitely a feature.
The above is the detailed content of PHP: no, its not possible. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon

Announcement of 2025 PHP Situation Survey
