CKTIS / PHP
WeakReference
Observa um objeto sem prolongar a sua vida. get devolve o mesmo objeto vivo e null após a destruição.
Versão: PHP 8.4; repository runtime, production runtime not attested
Sintaxe
WeakReference::create($object)Observa um objeto sem prolongar a sua vida. get devolve o mesmo objeto vivo e null após a destruição. Atribuir o resultado de get a outra variável cria por si só uma referência forte temporária.
$obj=new stdClass(); $weak=WeakReference::create($obj); $held=$weak->get(); unset($obj);
$alive=$weak->get()===$held; unset($held); echo json_encode([$alive,$weak->get()]);
[true,null]
Exemplos
<?php
$obj=new stdClass(); $weak=WeakReference::create($obj); $held=$weak->get(); unset($obj);
$alive=$weak->get()===$held; unset($held); echo json_encode([$alive,$weak->get()]);
Resultado
[true,null]