1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Implement GH-13609: Dump wrapped object in WeakReference class (#13621)

I chose "object" as that's also the argument name in WeakReference::create.
This commit is contained in:
Niels Dossche
2024-03-08 18:31:24 +01:00
committed by GitHub
parent e7888a46fa
commit d6d3370034
5 changed files with 57 additions and 3 deletions

1
NEWS
View File

@@ -15,6 +15,7 @@ PHP NEWS
. Fixed zend call stack size for macOs/arm64. (David Carlier)
. Added support for Zend Max Execution Timers on FreeBSD. (Kévin Dunglas)
. Ensure fiber stack is not backed by THP. (crrodriguez)
. Implement GH-13609 (Dump wrapped object in WeakReference class). (nielsdos)
- Curl:
. Deprecated the CURLOPT_BINARYTRANSFER constant. (divinity76)

View File

@@ -164,6 +164,8 @@ PHP 8.4 UPGRADE NOTES
. Added request_parse_body() function that allows parsing RFC1867 (multipart)
requests in non-POST HTTP requests.
RFC: https://wiki.php.net/rfc/rfc1867-non-post
. Getting the debug info for WeakReference will now also output the object
it references, or null if the reference is no longer valid.
- Curl:
. curl_version() returns an additional feature_list value, which is an

View File

@@ -26,9 +26,15 @@ object(stdClass)#1 (0) refcount(2){
}
object(stdClass)#1 (0) refcount(2){
}
object(WeakReference)#2 (0) {
object(WeakReference)#2 (1) {
["object"]=>
object(stdClass)#1 (0) {
}
}
object(WeakReference)#2 (0) {
object(WeakReference)#2 (1) {
["object"]=>
object(stdClass)#1 (0) {
}
}
object(stdClass)#1 (0) refcount(2){
}
@@ -36,4 +42,3 @@ object(stdClass)#1 (0) refcount(2){
}
NULL
NULL

View File

@@ -0,0 +1,26 @@
--TEST--
Weakrefs debug dump
--FILE--
<?php
$s = new stdClass;
$s->hello = 'world';
$weak = WeakReference::create($s);
var_dump($weak);
unset($s);
var_dump($weak);
?>
--EXPECT--
object(WeakReference)#2 (1) {
["object"]=>
object(stdClass)#1 (1) {
["hello"]=>
string(5) "world"
}
}
object(WeakReference)#2 (1) {
["object"]=>
NULL
}

View File

@@ -271,6 +271,25 @@ static void zend_weakref_free(zend_object *zo) {
zend_object_std_dtor(&wr->std);
}
static HashTable *zend_weakref_get_debug_info(zend_object *object, int *is_temp)
{
*is_temp = 1;
HashTable *ht = zend_new_array(1);
zend_object *referent = zend_weakref_from(object)->referent;
zval value;
if (referent) {
ZVAL_OBJ_COPY(&value, referent);
} else {
ZVAL_NULL(&value);
}
zend_hash_update(ht, ZSTR_KNOWN(ZEND_STR_OBJECT), &value);
return ht;
}
ZEND_COLD ZEND_METHOD(WeakReference, __construct)
{
zend_throw_error(NULL, "Direct instantiation of WeakReference is not allowed, use WeakReference::create instead");
@@ -749,6 +768,7 @@ void zend_register_weakref_ce(void) /* {{{ */
zend_weakref_handlers.offset = XtOffsetOf(zend_weakref, std);
zend_weakref_handlers.free_obj = zend_weakref_free;
zend_weakref_handlers.get_debug_info = zend_weakref_get_debug_info;
zend_weakref_handlers.clone_obj = NULL;
zend_ce_weakmap = register_class_WeakMap(zend_ce_arrayaccess, zend_ce_countable, zend_ce_aggregate);