Writing PHP Extensions1. Setting up Your PHP Build Environment on Linux2. Generating a PHP Extension Skeleton3. Building and Installing a PHP Extension4. Rebuilding Extensions for Production5. Extension Skeleton File Content6. Running PHP Extension Tests7. Adding New Functionality8. Basic PHP Structures9. PHP Arrays10. Catching Memory Leaks11. PHP Memory Management12. PHP References13. Copy on Write14. PHP Classes and Objects15. Using OOP in our Example Extension16. Embedding C Data into PHP Objects17. Overriding Object Handlers18. Answers to Common Extension Questions6. Running PHP Extension TestsIn addition to these four files, “ext_skel” script created a “tests” directory, with several *.phpt files inside it. These are automated tests that may be executed all together, by running the “make test” command:$ make test … ===================================================================== TEST RESULT SUMMARY --------------------------------------------------------------------- Exts skipped : 0 Exts tested : 26 --------------------------------------------------------------------- Number of tests : 3 3 Tests skipped : 0 ( 0.0%) -------- Tests warned : 0 ( 0.0%) ( 0.0%) Tests failed : 0 ( 0.0%) ( 0.0%) Tests passed : 3 (100.0%) (100.0%) --------------------------------------------------------------------- Time taken : 1 seconds =====================================================================The command will print the test execution progress and result summary. It’s a good practice to cover most extension logic with corresponding tests and always run tests after changes. Let’s investigate the test file “tests/003.phpt.” --TEST-- test_test2() Basic test --SKIPIF-- <?php if (!extension_loaded(‘test’)) { echo ‘skip’; } ?> --FILE-- <?php var_dump(test_test2()); var_dump(test_test2(‘PHP’)); ?> --EXPECT-- string(11) “Hello World” string(9) “Hello PHP”The file combines a few sections: “--TEST--” defines the test name. “--SKIPIF--” (optional) contains a PHP code to check skip conditions. If it prints some string, started from word “skip”, the whole test is going to be skipped. Our section prints “skip” if extension “test” is not loaded because it doesn’t make sense to check functions that are not loaded (the test would fail). “--FILE--” section contains the main test PHP code. “--EXPECT--” contains the expected output of the test script. Request PDF VersionBook traversal links for 6. Running PHP Extension Tests‹ 5. Extension Skeleton File ContentWriting PHP Extensions7. Adding New Functionality ›