Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49564 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49190 invoked from network); 3 Sep 2010 19:08:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Sep 2010 19:08:47 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:47831] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 67/27-04106-CB7418C4 for ; Fri, 03 Sep 2010 15:08:46 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id B6EE0700044A for ; Fri, 3 Sep 2010 20:08:41 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id 56x4eqiP71xm for ; Fri, 3 Sep 2010 20:08:41 +0100 (WEST) Received: from mail2.ist.utl.pt (mail2.ist.utl.pt [IPv6:2001:690:2100:1::c]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 559327000436 for ; Fri, 3 Sep 2010 20:08:41 +0100 (WEST) Received: from cataphract (a79-168-249-157.cpe.netcabo.pt [79.168.249.157]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 3A17C200860F for ; Fri, 3 Sep 2010 20:08:41 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: <81.35.47051.C61C08C4@pb1.pair.com> <2B.21.27233.A1ED08C4@pb1.pair.com> Date: Fri, 03 Sep 2010 20:07:02 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_IST?= Message-ID: In-Reply-To: <2B.21.27233.A1ED08C4@pb1.pair.com> User-Agent: Opera Mail/10.61 (Win32) Subject: Re: [PHP-DEV] Re: remove or fix zend_object_proxies From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Fri, 03 Sep 2010 12:37:58 +0100, Michael Wallner wrote: > OBJECTS2_HOWTO--okay maybe a tiny bit out of date, but > nevertheless--states > that for the get_property_ptr_ptr object handler, which is supposed to > return zval** of the property, one can use zend_proxy_objects for > properties not really existing as zvals. OBJECTS2_HOWTO is indeed out of date. For instance it refers to the handlers get_property_zval_ptr and get_property_ptr, which don't exist anymore. If I'm not mistaken, the current way to return proxy objects is to return NULL from get_property_ptr_ptr, forcing a fallback to read_property and return a proxy object from there (with refcount 0 if it's not referenced anywhere). > > This objects overload the get and set object handlers (note: not > __get/__set) > to enable something along the lines: > > class user_class extends internal_class { > function method() { > $ref = &$this->internal_property; > /* $ref now actually is a zend_proxy_object */ > $ref = 1; > } > } > > ... but no other object handler that add_ref, del_ref, clone_obj, get > and set are defined, which causes everything from fatal errors to SEGVs > on simple statements like var_dump, echo, (string)-cast etc... Yes, I've also noticed this breakage when writing the wiki page for objects ( http://wiki.php.net/internals/engine/objects ). Most from the code I've seen (I haven't actually programmed anything with proxy objects except for making some tests while writing that page), the problem is not so much the engine. Although the Zend engine also has some parts with poor proxy objects supports (e.g. I don't think you can use proxy objects as array indexes, even if the get handler would return an int/string), the problem is mostly the extensions, which frequently assume the handlers exist. The engine sometimes tries to protect against this -- Z_OBJCE/zend_get_class_entry check if get_class_entry exists before calling it, for instance --, but there are a lot of extensions that inadequately assume some handlers exist. Even var_dump assumes get_class_name exists... Those bugs should be fixed and extension writes should be aware they can be given proxy objects, but if you're worried about those segfaults, you can define dummy implementations for those handlers. zend_parse_parameters is also broken because it does not attempt to call the get handler when you pass a proxy object, except if you request a string (and even then, it prefers the cast_object handler). > Additionally on object destruction, at the latest on shutdown, > (the default) zend_objects_destroy_object causes a SEGV because > zend_proxy_objects actually are not zend_objects and don't have > a class entry. > I don't see the issue here. You should define an appropriate callback. If they're not zend standard objects, don't use zend_objects_destroy_object in your zend_objects_store_put call (or NULL, which defaults to zend_objects_destroy_object). The store accepts anything and even has a clone callback specifically to make easier the cloning of non-standard Zend objects. -- Gustavo Lopes