search
HomeBackend DevelopmentPHP7Weak 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;
}

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
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function