WeakReference class

(PHP 7 >= 7.4.0, PHP 8)


소개

약한 참조는 프로그래머가 개체에 대한 참조를 유지할 수 있도록 하여 개체가 파괴되는 것을 방지하지 않습니다. 캐시와 같은 구조를 구현하는 데 유용합니다.

WeakReference는 직렬화할 수 없습니다.


인터페이스 개요

                  
final class WeakReference {
  /* Methods */
  public __construct()
  public static create(object $object): WeakReference
  public get(): ?object
}
                  
                

Examples

예제 #1 WeakReference 사용법

                  
<?php
$obj = new stdClass;
$weakref = WeakReference::create($obj);
var_dump($weakref->get());
unset($obj);
var_dump($weakref->get());
?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

object(stdClass)#1 (0) {
}
NULL
                

목차