Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64641 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79314 invoked from network); 7 Jan 2013 17:15:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jan 2013 17:15:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.51 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.212.51 mail-vb0-f51.google.com Received: from [209.85.212.51] ([209.85.212.51:33825] helo=mail-vb0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 42/01-08897-6B20BE05 for ; Mon, 07 Jan 2013 12:15:34 -0500 Received: by mail-vb0-f51.google.com with SMTP id fq11so19909911vbb.10 for ; Mon, 07 Jan 2013 09:15:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=mpe7zkpYq6dCQvj5O4vOU6GxE9ymypcXCPv/nyROdNA=; b=rqCnqLvasP81kAdWlwtH3h+cn3t18GisGsbezjBN5NsZWBfFxyAEnopEae+MZNxNzR HjiXSYrZQ44aXmrSeO7+wMwOIjvhDUPt58Y8IKV+qN6RXEPjlGY6I78liqvRkLWJjveQ 1greuwlbmaVBqvYTGsl7TWcTbd7tOzZwzJqioLJ+Dsqn3Zbofw64k4bJzKTfdIdC6kvj UzeiDAPgFr2v5iKgHf2ZgYcKAEH8NeMs/M8MUoLPL2zHVJ5cas9fsV9G5T4beMJYrqLN tR0WYnHEtz97gyJxq+zYxwkYxMUeXW8FwRcpw6JSC3C/sgrtT4UkrVyNDWspEnjzm0dq j7+Q== MIME-Version: 1.0 Received: by 10.221.2.11 with SMTP id ns11mr82088733vcb.3.1357578931895; Mon, 07 Jan 2013 09:15:31 -0800 (PST) Received: by 10.58.56.137 with HTTP; Mon, 7 Jan 2013 09:15:31 -0800 (PST) In-Reply-To: <102501cdecf9$e427d540$ac777fc0$@starin.biz> References: <102501cdecf9$e427d540$ac777fc0$@starin.biz> Date: Mon, 7 Jan 2013 12:15:31 -0500 Message-ID: To: nathan@starin.biz Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=bcaec54ee7d8fd7cc304d2b5f9cb Subject: Re: [PHP-DEV] new Class ReflectionZVal From: ircmaxell@gmail.com (Anthony Ferrara) --bcaec54ee7d8fd7cc304d2b5f9cb Content-Type: text/plain; charset=ISO-8859-1 Nathan, On Mon, Jan 7, 2013 at 12:10 PM, wrote: > I wanted some thought from you guys about the idea of giving PHP scripts > the > ability to read some internal information about variables such as ZVals. > > > > The idea of how this reflection class would work would be something like: > > > > Class ReflectionZVal { > > // Retains info about the variable referenced > > function __construct(&$variable); > > // Returns if the referenced variable > > function valueExists(); > > // Returns a ref to the variable or throws error if value is gone. > > function &getValue(); > > // Returns the reference count of the variable > > function getRefCount(); > > // Returns the current type associated with the referenced variable > > function getType(); > > // Returns bool of if getValueReflection() is callable. (see note > below) > > function isValueReflectable(); > > // Returns a new instance of ReflectionZVal for the value of variable > passed in construct. (returns null and throws error if value is not a ref > of > a variable) > > function getValueReflection(); > > } > > > > The idea of this class would give PHP the ability to read reference count > info and have read-only access to values stored in variables without > causing > PHP to not be able to use the internal garbage collector. An example of how > this could be useful would be if you had a class structure that matched a > database table structure. Every time a new record of the table was returned > it constructed a new object. It is more practical to have the class store > each object that was constructed into a static variable attached to each > class structure and when a new record is requested it first checks to see > if > the object with the same row has already been constructed and use/update > that object instead of making (possibly) many duplicates. This gives the > code structure the ability that if the same record was requested then later > in the execution the same row was requested again and modified it would > also > modify it everywhere that object/row was already requested. The issue with > this structure is that php's garbage collector will never clean up those > constructed objects because the class needs a reference to them and cannot > know if other places in the code has references to them. > > > > If a reflection like this one was available it would give the ability to > contain a reference to variables/pointers without increasing the reference > count. It would allow a class structure (like stated above) to call it's > own > garbage collector every once in a while to clean up those ReflectionZVal > objects by checking the result of ReflectionZVal:: valueExists (). > > > > Is there anything obvious (limitation wise) that I am missing or is this > RFC'able? > This is an AWESOME idea. The only question that I'd have is whether it should be implemented in reflection or as a language construct. The former would have issues with pass-by-reference and reference counting (debugging a variable would actually cause a separation and make refcount useless for non-referenced variables)... The latter would require parser changes, but eliminate that issue (as it could access the compiled variable directly)... Then again, that's dirty as it requires new keywords in the language... But I love the concept... Anthony --bcaec54ee7d8fd7cc304d2b5f9cb--