Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102637 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61423 invoked from network); 7 Jul 2018 17:03:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jul 2018 17:03:52 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.47 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.47 mail-wm0-f47.google.com Received: from [74.125.82.47] ([74.125.82.47:35266] helo=mail-wm0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/14-55607-772F04B5 for ; Sat, 07 Jul 2018 13:03:51 -0400 Received: by mail-wm0-f47.google.com with SMTP id v3-v6so13377008wmh.0 for ; Sat, 07 Jul 2018 10:03:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=XfCZs0aSQa1weVEi+3v0Bq828N6UDmz8S75BDDBJIKE=; b=fqNVUtYonoi0kvrr1g+UXYr0/wYT78+pJMuxju8MJXKPdhI8jmnan4QaKFYYV2H+ME k1Sd0lTDgM5vd6tP6MqDeyt4ruWx+OdFyS5gAwgLXJPTihUBgYiCEEVKF+5c2irr7fdT 35LyT6mjZ90wVEtyT+1W2020oCY6vEZQWNLKSuBVFjWFmUkb5FQQk0k2H0hIeY2/1rBr a/KkUdX7onzEiJdlKr/xzSJyr4adPA7xbPp5ksMGfqRI9fBEEioaQeqzyNBBBDEhl0x1 7k0Z7xrHknNELxqyFOBb94lGAjCoiPIYYTEB4UO0yoLihXCHoKVY1mZOiBpqy+2qXDO+ 633w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=XfCZs0aSQa1weVEi+3v0Bq828N6UDmz8S75BDDBJIKE=; b=YJKEtvtOB7IvNX803kQeIQCLCpWFnrBUTurJQB61vL3cGca0YmIozTEJhdfmLhB22B jcr58VodkXj1Eb12tKkIQmoLxLl6MQNz+07XWImY8H8eK8qGLqa2BoDQ+H4VpK28DQ+Q QstYaP13tuoYXdOxwY+NPaWagujKXERBN6zPz/H77i9VOiafD9c8mD/GEH+KexjS9xfo q236PLnPeWitOyHla2YYvZQ/wR7WBCG2YFZjIy5RX9ZopSqMhbSK1vX/QopIhfZItqa/ sOESx/iZMIOUbqjzzjNjUSTb9bDdpEtenKBGSJ+igmYGEI2hhxyy7hoLPLklso97HVCM 9elg== X-Gm-Message-State: APt69E0y3KJvwAMWyfXKVDIBqWNUrpNILL5QikL/xQzIhTuTxErzWqZA ZNXkf27Hpym8OSF9hcczWRiLwXKa X-Google-Smtp-Source: AAOMgpeMsYExkHyCvA8bmg9qVtU5fU/Srj65cGMga1iSxYjTm00Ls/lzwmGdT7f8vNey/Lo8CnmY7Q== X-Received: by 2002:a1c:9ec5:: with SMTP id h188-v6mr9548347wme.76.1530983028149; Sat, 07 Jul 2018 10:03:48 -0700 (PDT) Received: from ?IPv6:2a00:23c4:4b86:4b00:e4d4:26d7:4edd:8c8c? ([2a00:23c4:4b86:4b00:e4d4:26d7:4edd:8c8c]) by smtp.googlemail.com with ESMTPSA id 24-v6sm29069961wrz.94.2018.07.07.10.03.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Jul 2018 10:03:47 -0700 (PDT) To: internals@lists.php.net References: Message-ID: Date: Sat, 7 Jul 2018 18:03:42 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] [RFC] Typed Properties From: rowan.collins@gmail.com (Rowan Collins) On 06/07/2018 21:57, Nicolas Grekas wrote: > >> if ((new ReflectionReference($array[$key]))->getRefcount() > 2) { > I just realized that this interface would suffer from a significant > drawback: it would trigger COW when iterating over immutable arrays, > defeating the shared-memory optimization provided by OPcache. Any implementation of this that acts like a normal function / constructor call is going to suffer from the same problems as debug_zval_dump: passing a variable from one scope to another will change the properties of that variable. If you accept the variable by reference, you'll duplicate the data if it's part of a COW set (which has nothing to do with OpCache by the way, it's been a core part of the engine since at least 5.0); if you accept it by value, you'll duplicate the data if it's part of a reference set. Either way, you're going to change the refcount on the zval, hence the awkward 2 in Bob's example. Previous discussions of that function concluded that the only "correct" way to implement this would be as a language feature rather than a true function - if the compiler issues a specific OpCode, it can pull the zval straight out of the symbol table, without interfering with it. Maybe the two concepts could be combined, and the language feature generate a Reflection object? e.g. $reflection = reflect_variable($var); if ( $reflection->isReference() ) {     $types = $reflection->getReferencedTypes(); } > An interface like new ReflectionReference($array, $key) would be free from > the issue. Combined with get_defined_vars() and the (array) operator for > objects, we can inspect any PHP data structure or scope also this way. Yuck. Even if this solves the issue of supporting both ref and non-ref variables, you still end up having to compensate for the wrong refcount, and the resultant code would be ugly as sin. Regards, -- Rowan Collins [IMSoP]