Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102698 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86031 invoked from network); 10 Jul 2018 10:30:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jul 2018 10:30:42 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.52 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.52 mail-it0-f52.google.com Received: from [209.85.214.52] ([209.85.214.52:32959] helo=mail-it0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1A/F0-15421-0DA844B5 for ; Tue, 10 Jul 2018 06:30:40 -0400 Received: by mail-it0-f52.google.com with SMTP id y124-v6so14457003itc.0 for ; Tue, 10 Jul 2018 03:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=cowh1tTGT+ggqXSXGYSll4XQHLtbu+qZm5ft0e3jdvg=; b=N9a3o7+ORQDKT/qRkN8jpUHYst9kl8mG2hyj0+9l+hP+4k8zZXQHjKvzxdS3sieRMa KaDKAO42HRduyt3kmv8GOXVY4BKXzTVawZEf9aFOXXo0SQE0Cq0miS6qtmu2YahJKu1+ B4Fa/bvmpvKs13ylxm1ZSPkrTyby7N1f4QkbJlLc5K5ZvwsymQnjDrMG+OnOu3/C9HoE nzGcwwPuyHKsVdYbMyvnCJfUkicTRZVYvKb7yl88ksRN2MghQiQKK+8Eb/y1o1X/onLv Psm8sKtzEYoOXahUw+Xbcm5sq41I+PtRSy7313mbYtMpUaFweDjaJMCFBBc0itSHpNZf 0cAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=cowh1tTGT+ggqXSXGYSll4XQHLtbu+qZm5ft0e3jdvg=; b=tXayk/XzGy/IJi0WBsjPxnxRyppHU+YbzENszaN1/uqGFXOWzWIVfcOEegZvcrE3V/ vKZoiEQj82Ez+Ixv5Kl09jhMHPwyjQslSx7DfmYg3F8moX7C96T/KeF0lGLE2d/mJOXF 70VcjCT57EYz7mq9l6IlLx+8YXvEdjHrwSAJ9spFVuY9Q0M8F6q1D9wSzVaOkjK2v+ni MkDtv/6Zn/bQRaQVCfjKl2Tea8aPAyTmDUpSiWxoPBWFmMiIwrOVw/RUnU0pgwVxwnR2 Ye4FVbJ84t+msCh5wixCEilpmxFsmrVz/LVNxEgHGf2sxCZ7YC2jxIUnJm6Nh68uW6r0 DNYQ== X-Gm-Message-State: APt69E18saYipS+leJAvDD4ZZRLbd4bQIAhbVxwV6vvRCIfdsz0DWDbj jqkWqXbQKKRCGGhqWCWuuSUZ5ADtK4QUiVJWeJQ= X-Google-Smtp-Source: AAOMgpde6vP+dMFIroQUuG2GTDfROY97eJkdmO/p740YJoVGiSmoEJeGXB+gSKtFvyzNfL6mmWvkrW+G0Yu+3EQPaN8= X-Received: by 2002:a24:3c41:: with SMTP id m62-v6mr18118475ita.63.1531218638147; Tue, 10 Jul 2018 03:30:38 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:148a:0:0:0:0:0 with HTTP; Tue, 10 Jul 2018 03:30:37 -0700 (PDT) In-Reply-To: References: Date: Tue, 10 Jul 2018 12:30:37 +0200 Message-ID: To: Nicolas Grekas Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000000014d10570a29f1b" Subject: Re: [PHP-DEV] Introspection for references From: nikita.ppv@gmail.com (Nikita Popov) --0000000000000014d10570a29f1b Content-Type: text/plain; charset="UTF-8" On Tue, Jul 10, 2018 at 12:15 PM, Nicolas Grekas < nicolas.grekas+php@gmail.com> wrote: > If we're seeking for a benefit, it would be by turning this to a >>> ReflectionZval insteaf of ReflectionReference. There would be isRef, but >>> also getType, etc. But honeslty I'm with you on this, only refs make sense. >>> >> >> I'm wondering if there is any legitimate use for something like this. The >> only thing that comes to mind is comparing arrays by identity. E.g. >> https://github.com/symfony/symfony/blob/master/src/Symfony/ >> Component/VarDumper/Cloner/VarCloner.php#L153 could check directly check >> whether an array is the $GLOBALS array. It would also allow direct >> recursion detection on arrays (ref https://stackoverflow.com/ques >> tions/9105816/is-there-a-way-to-detect-circular-arrays-in-pure-php). >> Doing the same on just references is nearly the same, but doesn't handle >> the $GLOBALS case correctly. >> > > Note that AFAIK, not only $GLOBALS has a special behavior, but also any > "scope" array (the deprecated $context argument of error handlers at least, > maybe what get_defined_vars() also? > > If we can return this info, I would definitely leverage it. > If not, that's no blocker, I'll let you decide. > > > >> There is a 4th possibility: have a "ReflectionReference::getHash" method, >>> that would return a unique string/id per reference (what >>> symfony_zval_debug() does.) >>> >> >> Is this the same as my 3rd suggestion with a different name >> > > No, it's the same, I read too fast. > > > >> we could return the address hashed with a per-process key. This would >> make the function somewhat slower though. >> > > That's exactly what we do in our extension, inspired by spl_object_hash(). > On the perf side, a XOR should be OK :) > Unfortunately XOR is about as good as just returning the address directly. XORing the value is basically doing a one-time-pad without the "one-time" part, aka completely broken. If we wanted to actually hide the address, we'd have to run it through a proper hash. (Then again, you are right that spl_object_hash used to do this, so maybe we just don't care...) Nikita --0000000000000014d10570a29f1b--