get_property_ptr

php.internals

Sterling Hughes

23 years ago
hey, I'm working on simplexml (sources available in pecl), and I want it to work in a foreach() loop without requiring the use of a temporary variable, ie: books.xml <books> <book> <title>The Grapes of Wrath</title> <author>John Steinbeck</author> </book> <book> <title>The Pearl</title> <author>John Steinbeck</author> </book> </books> books.php <?php $books = simplexml_load_file('books.xml'); $booklist = $books->book; // must assign to a temporary variable foreach ($booklist as $book) { echo "{$book->title}\n"; } ?> So I'm trying to figure out how to use the get_property_ptr callback. I've tried a few things: 1) zend_object_create_proxy. The docs say I can just return a proxy object, however, this causes a segfault for me: return zend_object_create_proxy(object, member TSRMLS_CC); 2) Adding indirection. I just call property_read, and then return a pointer to the result of the property_read call. This also yields a segfault. So, any insights on how I might be a smarter boy, and actually get this thingy to work? :) -Sterling
-- "Whether you think you can or think you can't -- you are right." - Henry Ford

(Marcus Börger)

23 years ago
At 22:27 18.05.2003, Sterling Hughes wrote:
>hey, > >I'm working on simplexml (sources available in pecl), and I want it to >work in a foreach() loop without requiring the use of a temporary >variable, ie: > >[...] > >So, any insights on how I might be a smarter boy, and actually get this >thingy to work? :)
Just look into SPL cvs co spl and implement spl::foreach with you object the php5 version of sqlite does that and it is working fine :-) regards marcus

Sterling Hughes

23 years ago
On Sun, 2003-05-18 at 18:11, Marcus Börger wrote:
> At 22:27 18.05.2003, Sterling Hughes wrote: > >hey, > > > >I'm working on simplexml (sources available in pecl), and I want it to > >work in a foreach() loop without requiring the use of a temporary > >variable, ie: > > > >[...] > > > >So, any insights on how I might be a smarter boy, and actually get this > >thingy to work? :) > > > Just look into SPL > cvs co spl > and implement spl::foreach with you object > the php5 version of sqlite does that and it is working fine :-) >
Hmm? I'm not looking to overload the opcodes, just to make the object callback work so that foreach() can happen naturally. So, I want to actually implement a good get_property_ptr, not make get_property_ptr unnecessary :) -Sterling
> regards > marcus
-- "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup

Andrei Zmievski

23 years ago
On Sun, 18 May 2003, Sterling Hughes wrote:
> Hmm? I'm not looking to overload the opcodes, just to make the object > callback work so that foreach() can happen naturally. So, I want to > actually implement a good get_property_ptr, not make get_property_ptr > unnecessary :)
Sterling, Last time I checked the proxy system was broken. I've emailed Stas about it a couple of times, but apparently he's been busy with other things. -Andrei http://www.gravitonic.com/ Nobody tried to design Windows - it just grew in random directions without any kind of thought behind it.

Derick Rethans

23 years ago
On Mon, 19 May 2003, Andrei Zmievski wrote:
> On Sun, 18 May 2003, Sterling Hughes wrote: > > Hmm? I'm not looking to overload the opcodes, just to make the object > > callback work so that foreach() can happen naturally. So, I want to > > actually implement a good get_property_ptr, not make get_property_ptr > > unnecessary :) > > Last time I checked the proxy system was broken. I've emailed Stas about > it a couple of times, but apparently he's been busy with other things.
Just like __clone() still segfaults :I Derick
-- "my other box is your windows PC" ------------------------------------------------------------------------- Derick Rethans http://derickrethans.nl/ International PHP Magazine http://php-mag.net/ -------------------------------------------------------------------------