Home Backend Development PHP Tutorial PHP: no, it&#s not possible

PHP: no, it&#s not possible

Jul 19, 2024 pm 02:14 PM

PHP: no, it

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.

PHP doesn't support multiple inheritance

You simply cannot do the following:

class Child extends Parent1, Parent2 {}
Copy after login

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 {}
Copy after login

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, it&#s not possible. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

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

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

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

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

Announcement of 2025 PHP Situation Survey

See all articles