05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

zend_hash_update(&EG(symbol_table), "foo", sizeof("foo"),<br />

&var, sizeof(zval *), NULL);<br />

}<br />

The arguments to zend_hash_update( ) should be self-explanatory, except for that<br />

final NULL. To get back the address of the new container, pass a void ** instead of<br />

NULL; the void * whose address you pass will be set to the address of the new container.<br />

Typically, this last argument is always NULL.<br />

Extension INI Entries<br />

Defining php.ini directives (i.e., INI entries) in an extension is easy. Most of the work<br />

involves setting up the global struct explained earlier in the section “Internal Extension<br />

Globals.” Each entry in the INI structure is a global variable in the extension<br />

and thus has an entry in the global struct and is accessed using FOO_G(my_ini_<br />

setting). For the most part you can simply comment out the indicated sections in<br />

the skeleton created by ext_skel to get a working INI directive, but we will walk<br />

through it here anyway.<br />

To add a custom INI entry to your extension, define it in your main foo.c file using:<br />

<strong>PHP</strong>_INI_BEGIN( )<br />

STD_<strong>PHP</strong>_INI_ENTRY("foo.my_ini_setting", "0", <strong>PHP</strong>_INI_ALL, OnUpdateInt,<br />

setting, zend_foo_globals, foo_globals)<br />

<strong>PHP</strong>_INI_END( )<br />

The arguments to the STD_<strong>PHP</strong>_INI_ENTRY( ) macro are: entry name, default entry<br />

value, change permissions, pointer to change modification handler, corresponding<br />

global variable, global struct type, and global struct. The entry name and default<br />

entry value should be self-explanatory. The change permissions parameter specifies<br />

where this directive can be changed. The valid options are:<br />

<strong>PHP</strong>_INI_SYSTEM<br />

The directive can be changed in php.ini or in httpd.conf using the php_admin_<br />

flag/php_admin_value directives.<br />

<strong>PHP</strong>_INI_PERDIR<br />

The directive can be changed in httpd.conf or .htaccess (if AllowOverride OPTIONS<br />

is set) using the php_flag/php_value directives.<br />

<strong>PHP</strong>_INI_USER<br />

The user can change the directive using the ini_set( ) function in scripts.<br />

<strong>PHP</strong>_INI_ALL<br />

A shortcut that means that the directive can be changed anywhere.<br />

The change modification handler is a pointer to a function that will be called when<br />

the directive is modified. For the most part, you will probably use one of the built-in<br />

change-handling functions here.<br />

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

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

Extension INI Entries | 347

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

Saved successfully!

Ooh no, something went wrong!