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.
Comments: nabeel [at] php.net
- Echo extension
This example shows how to write a procedural style PHP extension.
- Time extension
This example shows how to write an object oriented style PHP extension.
- Understanding the zval
This example uses the macros defined in PHP to determine the type of variables and access the values stored in them.
- Passing arguments
This example shows different ways passing arguemnts in to a function.
- Returning values
This example shows the macros used to return values from functions
- Global values
This example shows how declare, initailize and use global variables in your extension.
- INI settings
This example shows how to programmatically manipulate ini entries.
- Working with arrays
This example shows how to create, use and destroy arrays in PHP extensions.
- Calling userland functions
This example shows you how to access functions defined in a PHP script.
- Working with resources
This example gives you enough information to get started with using resources in your real extensions.