Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:74765 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36028 invoked from network); 5 Jun 2014 22:26:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jun 2014 22:26:47 -0000 Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.215.10 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.215.10 mail.experimentalworks.net Received: from [217.114.215.10] ([217.114.215.10:48952] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/71-28596-3AEE0935 for ; Thu, 05 Jun 2014 18:26:44 -0400 Received: from [192.168.2.31] (ppp-93-104-17-233.dynamic.mnet-online.de [93.104.17.233]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: johannes@schlueters.de) by mail.experimentalworks.net (Postfix) with ESMTPSA id 4CD3D40D41; Fri, 6 Jun 2014 00:26:42 +0200 (CEST) To: Nicolai Scheer Cc: PHP Internals In-Reply-To: References: <1401917648.2282.175.camel@guybrush> Content-Type: text/plain; charset="UTF-8" Date: Fri, 06 Jun 2014 00:26:19 +0200 Message-ID: <1402007179.2282.209.camel@guybrush> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] zend_API.c - missing zend_update_property_resource From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) On Thu, 2014-06-05 at 21:21 +0200, Nicolai Scheer wrote: > > * resources are handled as zvals, thos can be passed by > > zend_update_property(). The other are just wrappers creating the > > zval first. > > > > Of course it is no big deal to use zend_update_property and create the zval > myself :) I think you'd have to pass all arguments of ZEND_REGISTER_RESOURCE to such a function. For that to work you'd need the resource type identifier. (le_foo), which usually is static in a C file, thus you could use it only in few cases, which seem unlikely to me considering resources being discouraged (see below) > > * Usage of resources is discouraged, instead of a resource use an > > object (extend zend_object to store pointers etc.) > > > > Didn't know that usage of resources was discouraged... Nearly all my > knowledge comes from Sara's great book (btw. if you read this Sara, I'd > love to see and buy a refreshed version!) and my own field tests. > When you say "use an object", do you refer to the way described in [1]? > From what I've read so far, this way sounds more complex than just > registering a resource. > Could you elaborate a bit on the rationale behind this recommendation? They are (incomplete list) * slower than objects for many operations * have an api with some weird behavior (some operations give errors which are hard to catch as extension author) * any people consider OO APIs nicer * resources can't be introspected by PHP level debuggers, var_dump etc. whereas objects can provide required hooks (For the performance aspect I once created an extension for a quick demonstration http://marc.info/?l=pecl-dev&m=135774573910117&w=2 https://github.com/johannes/resvsobj ) > [1] > http://www.phpinternalsbook.com/classes_objects/custom_object_storage.html http://www.phpinternalsbook.com/classes_objects/custom_object_storage.html#overriding-create-object is the relevant section. johannes