# get_property_ptr

- Thread: https://externals.io/message/1683
- Original archive: https://news-web.php.net/php.internals/1683
- Started by Sterling Hughes on 2003-05-18T20:27:21+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #1683 — Sterling Hughes — 2003-05-18T20:27:21+00:00

URL: https://externals.io/message/1683#1683

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

---

## #1685 — marcus.boerger@t-online.de — 2003-05-18T22:11:30+00:00

URL: https://externals.io/message/1683#1685 · In reply to: #1683

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
