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.

zend_module_entry rot13_module_entry = {<br />

STANDARD_MODULE_HEADER,<br />

"rot13",<br />

rot13_functions,<br />

<strong>PHP</strong>_MINIT(rot13),<br />

<strong>PHP</strong>_MSHUTDOWN(rot13),<br />

NULL,<br />

NULL,<br />

<strong>PHP</strong>_MINFO(rot13),<br />

"0.1", /* replace with version number for your extension */<br />

STANDARD_MODULE_PROPERTIES<br />

};<br />

The extension API changed between <strong>PHP</strong> 4.0.x and <strong>PHP</strong> 4.1.x. To make your extension<br />

be source-compatible with <strong>PHP</strong> 4.0.x, you need to make some of the elements<br />

of the structure conditional, as follows:<br />

zend_module_entry rot13_module_entry = {<br />

#if ZEND_MODULE_API >= 20010901<br />

STANDARD_MODULE_HEADER,<br />

#endif<br />

"rot13",<br />

rot13_functions,<br />

<strong>PHP</strong>_MINIT(rot13),<br />

<strong>PHP</strong>_MSHUTDOWN(rot13),<br />

NULL,<br />

NULL,<br />

<strong>PHP</strong>_MINFO(rot13),<br />

#if ZEND_MODULE_API >= 20010901<br />

"0.1",<br />

#endif<br />

STANDARD_MODULE_PROPERTIES<br />

};<br />

Next in the rot13.c file is commented code showing how to deal with php.ini entries.<br />

The rot13 extension doesn’t need to be configured via php.ini, so leave them commented<br />

out. The later section “Extension INI Entries” explains the use of these<br />

functions.<br />

Next comes implementations of the MINIT( ), MSHUTDOWN( ), RINIT( ), RSHUTDOWN( ),<br />

and MINFO( ) functions. For our simple rot13 example, we simply need to return<br />

SUCCESS from the MINIT( ) and MSHUTDOWN( ) functions, and we can get rid of the<br />

RINIT( ) and RSHUTDOWN( ) functions entirely. So, after deleting some commented<br />

code, we just have:<br />

<strong>PHP</strong>_MINIT_FUNCTION(rot13) {<br />

return SUCCESS;<br />

}<br />

<strong>PHP</strong>_MSHUTDOWN_FUNCTION(rot13) {<br />

return SUCCESS;<br />

}<br />

<strong>PHP</strong>_MINFO_FUNCTION(rot13) {<br />

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

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

Building Your First Extensions | 323

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

Saved successfully!

Ooh no, something went wrong!