Home Backend Development PHP7 Weak References in PHP 7.4

Weak References in PHP 7.4

Nov 30, 2019 pm 02:28 PM
PHP 7.4

Weak References in PHP 7.4

Introduction

Weak references allow programmers to retain references to objects without This object does not prevent the object from being destroyed; they are useful for implementing cache-like structures. They currently have extended support in PHP.

Current implementations of WeakRef are implemented by overloading object handlers. The most popular implementation (pecl-weakref) changes the stack allocated to read-only memory, and PHP 7.3 will make it unavailable. Other implementations that change object handlers in other ways also run the risk of breaking and relying on undefined behavior and throwing away consistency.

Other implementations are possible, krakjoe/uref is an implementation that uses low-level features (mprotect, 0xCC, signals) to implement weakrefs, but at the cost of portability, generation of segmentation faults, protected memory and implicit Signal handler limitations.

In principle, weak reference objects are not complicated, just (ab)using Zend or the layer below, since we don't support it directly.

Recommendation

We directly support weak references in the simplest way.

API

The API:

final class WeakReference {
    public static function create(object $object) : WeakReference;
 
    public function get() : ?object;
}
Copy after login

Backward-incompatible changes

None.

Translation: https://wiki.php.net/rfc/weakrefs

The above is the detailed content of Weak References in PHP 7.4. 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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

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)