05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

And here’s a my_get( ) function that takes a resource parameter returned from my_<br />

init( ) and uses that to look up the data associated with the resource:<br />

<strong>PHP</strong>_FUNCTION(my_get)<br />

{<br />

test_le_struct *test_struct;<br />

zval *res;<br />

}<br />

if (zend_parse_parameters(ZEND_NUM_ARGS( ) TSRMLS_CC, "r", &res)<br />

== FAILURE) {<br />

return;<br />

}<br />

ZEND_FETCH_RESOURCE(test_struct, test_le_struct *, &res, -1, "test",<br />

le_test);<br />

if(!test_struct) RETURN_FALSE;<br />

array_init(return_value);<br />

add_assoc_string(return_value, "name", test_struct->name, 1);<br />

add_assoc_long(return_value, "age", test_struct->age);<br />

Where to Go from Here<br />

This is by no means a complete reference to the entire extension and Zend APIs, but<br />

it should get you to the point where you can build a simple extension. Through the<br />

beauty of open source software, you will never lack example extensions from which<br />

to borrow ideas. If you need a feature in your extension that you have seen a standard<br />

<strong>PHP</strong> function do, simply go have a look at how it was implemented. All the<br />

built-in features in <strong>PHP</strong> use the same API.<br />

Once you have gotten to the point where you understand the basic aspects of the<br />

extension API and you have questions about more advanced concepts, feel free to<br />

post a message to the <strong>PHP</strong> developers’ mailing list. The address is php-dev@lists.php.<br />

net. You do not need to be subscribed to send a question to this list. Note that this<br />

list is not for questions about developing applications written in user-level <strong>PHP</strong>. This<br />

is a very technical list about the internals of <strong>PHP</strong> itself. You can search the archives of<br />

this list on http://www.php.net by entering a search string in the search field and<br />

selecting this list. You can subscribe to this list, and all the other <strong>PHP</strong> lists, at http://<br />

www.php.net/support.php.<br />

Good luck with your <strong>PHP</strong> extension, and if you write something really cool, please<br />

tell us about it on the developers’ list!<br />

350 | Chapter 14: Extending <strong>PHP</strong><br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!