You 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.
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.
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 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?
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!