Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64642 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80765 invoked from network); 7 Jan 2013 17:18:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jan 2013 17:18:27 -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.215.42 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-la0-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:40192] helo=mail-la0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 82/51-08897-0630BE05 for ; Mon, 07 Jan 2013 12:18:25 -0500 Received: by mail-la0-f42.google.com with SMTP id fe20so16560673lab.29 for ; Mon, 07 Jan 2013 09:18:21 -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=rDMBoAyd0vGzD7ZXYPFP/EQy2bzUT1qil0pDfzTHKmU=; b=xoNQfMSru0dfOz3pEcAD5YsitnNEXnXqZTJJ+8bfkXa2luiUKwTAExU64iVfXf5dHj EFnI3jDv2qCDkS0uXev6oQLD6i6SJw3/igHYSg6nREP/J7bHxFQ0C4MhMGuJXI/62b1P 9gaw/uWb40Jr1lQdwZJN0mQsGzauEzu8Pku+LY/tgQgW8ub5wsBc7DnoLJMdQHk//IlZ l0zc+LfqhKBt6t1Vip7NisEtit4WZdE8cgEf1TMp3or3Qam23FKLBMOIZxp+Z6MmFE3A /LOz1P1xfMK19mGHeOomhxAO6RU8DsuDVnynRK0UahxLpKQs2K3r7vXgycynBlQe/WCy NOzA== MIME-Version: 1.0 Received: by 10.152.105.203 with SMTP id go11mr58615971lab.53.1357579101099; Mon, 07 Jan 2013 09:18:21 -0800 (PST) Received: by 10.112.4.168 with HTTP; Mon, 7 Jan 2013 09:18:20 -0800 (PST) In-Reply-To: <102501cdecf9$e427d540$ac777fc0$@starin.biz> References: <102501cdecf9$e427d540$ac777fc0$@starin.biz> Date: Mon, 7 Jan 2013 18:18:20 +0100 Message-ID: To: nathan@starin.biz Cc: PHP internals Content-Type: multipart/alternative; boundary=f46d04083e331358fc04d2b6048c Subject: Re: [PHP-DEV] new Class ReflectionZVal From: nikita.ppv@gmail.com (Nikita Popov) --f46d04083e331358fc04d2b6048c Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jan 7, 2013 at 6: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? > > > > Software Developer > > Nathan Bruer > I think what you are looking for here is a weak ref. See http://pecl.php.net/package/Weakref Nikita --f46d04083e331358fc04d2b6048c--