Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117508 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 57307 invoked from network); 9 Apr 2022 14:20:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Apr 2022 14:20:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 656331804B3 for ; Sat, 9 Apr 2022 08:51:53 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 9 Apr 2022 08:51:53 -0700 (PDT) Received: by mail-lj1-f169.google.com with SMTP id g24so14982547lja.7 for ; Sat, 09 Apr 2022 08:51:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=EBTCoyNHaRrHp1XI1zYMRMibfBMPQqd3af+gZbb4w/o=; b=R15QixLQCNsm1GeihJeuJAKMNfB5hqsZLoA1FaeaQbZgeh28o8Ll10tgSJKbMxP3rw kkMsEdLkh+HaHkiD+T8Bif5yLldH4LDWUvG5/n4RcqFQBWgVrAwRuxzgceWxJtDoecYd O7KUb5IKoOWH6GXKTt3+pHP0lhLLdq1YFTAT80MvYAMxIpDm18b/jpMfvHvwTZasC0m1 gD2/r5e2Su049pjiLcRp4+jSJtS7bWaCynRpzYeDNXcITKGNB+KtGMKq7fbBoicVjRc1 zvYjOgTaMBQ6P1wgTsBEp9DBgdj5UAFx+tG4fXYzA5O++PCd34d1cueH1vn50rCfUHTu h67Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=EBTCoyNHaRrHp1XI1zYMRMibfBMPQqd3af+gZbb4w/o=; b=E053QznUOMZYputFCe6v79rOpZo7+WRTbKqZnq2YHeOEF4tke3x2EYOLAMKG2NYvpR ZRbZFXUDAax3ioTrtsb08pz8Zl8Z4qTLrrXOdiqWPQWfl2Ng8hdGXrsDwJf2GScLhK5j ZKSsI3eK6nWI2hduajLlgeLg5EArwk6+wK2hovP8X6Vij9OzTI+EEULzU30VMtKhcbT1 qZgvLj4JsHaBthoeE4SfuPZtXaCDQdhT3psKA95ogVKvwGt9SZYeA3giA3Jo4wbeh57Y iO4oXGWhaEL8pt6AD/dNObCkJwuqwEXcRpTFZ1XLCpJ3g4MJYcVcpGPS/SanPjSe7Uhh PUiQ== X-Gm-Message-State: AOAM530PyjRfKosk3Cgq1Fn9Wpq0c1BRfCsS6oLszc1uIK2YSGy5g7TH Yd1TFF5xXc/EOeF3Dd/Q48SMoskAoO4enLkwbQvkyZmspj4= X-Google-Smtp-Source: ABdhPJxVLZmuiLzAwyfyFO4cPm5qGig3bG3zq8XkQ+eRx8UUU2Nas8jZlvNBCFfK6j2Oi7Pv/28Jltg/tOAg6rK7fbg= X-Received: by 2002:a05:651c:892:b0:249:9e23:15 with SMTP id d18-20020a05651c089200b002499e230015mr14875459ljq.492.1649519511172; Sat, 09 Apr 2022 08:51:51 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 9 Apr 2022 17:51:39 +0200 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000083797205dc3ab046" Subject: Re: unset a reference of property object From: glash.gnome@gmail.com (Glash Gnome) --00000000000083797205dc3ab046 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Out of politeness I answer myself, PHP_FUNCTION(var_dump) -> php_var_dump() -> zend_std_get_properties_for() // Zend object handler get_properties_for -> obj->handlers->get_debug_info(obj, &is_temp); // Zend object handler get_debug_info -> zend_std_get_properties();// Zend object handler get_properties -> rebuild_object_properties() -> _zend_hash_append_ind() =3D> ZVAL_INDIRECT(&p->val, ptr); // do the trick( Z_TYPE change) TODO: Find out how to manage the IS_INDIRECT So to reproduce the default php behavior I can implement the get_debug_info handler. I'm still trying to figure out how to modify this line : void my_get_debug_info() { // ... // Z_REFCOUNT(intern->data)=3D=3D1 // Z_TYPE(intern->data)=3D=3DIS_REFERENCE // Z_TYPE(Z_REF(intern->data)->val)=3D=3DIS_ARRAY zval zdata; ZVAL_COPY(&zdata, &intern->data);// Why do I have to hide that it's a reference ? zend_hash_str_update(debug_info, "data", sizeof("data")-1, &zdata); // ... return debug_info; } my_handlers.get_debug_info =3D my_get_debug_info; struct _my {// intern structure zval data;// array of unsigned int zend_object std; }; Le sam. 9 avr. 2022 =C3=A0 15:42, Glash Gnome a =C3= =A9crit : > Hello, > > I am developing a PHP extension. I can't reproduce the behavior of > references of Zend/PHP. > > Here is some Code illustrating Zend's behavior: > class Foo { public $baz =3D array(1);} > $foo =3D new Foo(); > $ref =3D &$foo->baz; > $foo->baz =3D [123];//set array has reference > var_dump($foo); > > Output ------------------------ > object(Foo)#1 (1) { > ["baz"]=3D> > &array(1) { [0]=3D> int(123) } > } > -------------------------------- > Note the symbol ( &) output from the var_dump(); > > > Now I add unset($ref) in my code > class Foo { public $baz =3D array(1);} > $foo =3D new Foo(); > $ref =3D &$foo->baz; > //unset($ref);// kill reference > $foo->baz =3D [123];// set array has reference > unset($ref) ;// kill reference > var_dump($foo); > ------------------------ > object(Foo)#1 (1) { > ["baz"]=3D> > array(1) { [0]=3D> int(123) } > } > -------------------------------- > > Note that the symbol (&) has disappeared from the output of var_dump(); > > I would like to reproduce this behavior but I don't know which method of > zend_object_handlers allows to remove( Z_UNREF) the reference. > > Thank you for your help > > > --00000000000083797205dc3ab046--