Re: zend_API.c - missing zend_update_property_resource

From: Date: Thu, 05 Jun 2014 22:26:19 +0000
Subject: Re: zend_API.c - missing zend_update_property_resource
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-74765@lists.php.net to get a copy of this message
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] > x > çÊGr¦¼¿ÎUVœ`Â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

« previous php.internals (#74765) next »