Extending PHP
Examples
The following examples illustrate some important points helpful to extend PHP. The first two examples provides a feeling of how to write a basic procedural and an object oriented extention. The rest of the examples focus on the language constructs involved in writing your own extensions. All the samples are written on Linux platform (but can easily be run on MS Windows) and tested with PHP 5.1.4. Please go through the README file bundled with each example to understand how it works.
- Echo extension
This example shows how to write a procedural style PHP extension.
Download echo.tar.gz
- Time extension
This example shows how to write an object oriented style PHP extension.
Download time.tar.gz
- Understanding the zval
This example uses the macros defined in PHP to determine the type of variables and access the values stored in them.
Download zval_demo.tar.gz
- Passing arguments
This example shows different ways passing arguemnts in to a function.
Download passing_arg_demo.tar.gz
- Returning values
This example shows the macros used to return values from functions
Download ret_val_demo.tar.gz
- Global values
This example shows how declare, initailize and use global variables in your extension.
Download global_val_demo.tar.gz
- INI settings
This example shows how to programmatically manipulate ini entries.
Download ini_settings_demo.tar.gz
- Working with arrays
This example shows how to create, use and destroy arrays in PHP extensions.
Download arr_demo.tar.gz
- Calling userland functions
This example shows you how to access functions defined in a PHP script.
Download calling_userland_demo.tar.gz
- Working with resources
This example gives you enough information to get started with using resources in your real extensions.
Download res_demo.tar.gz
Comments: nabeel [at] php.net