https://swig.svn.sourceforge.net/svnroot/swig/trunk ................ r10487 | wsfulton | 2008-05-21 23:15:52 +0100 (Wed, 21 May 2008) | 1 line Apply patch from Petr Viktorin to fix some recent regressions in CFFI/CLOS ................ r10498 | talby | 2008-05-26 21:09:56 +0100 (Mon, 26 May 2008) | 2 lines run test cases in the Perl set by the --with-perl5 configure option. ................ r10499 | talby | 2008-05-26 22:04:06 +0100 (Mon, 26 May 2008) | 3 lines The perl5 minherit runtime test will work better if the classes are actually built under SWIGPERL. ................ r10503 | wsfulton | 2008-05-28 10:44:37 +0100 (Wed, 28 May 2008) | 1 line Fix variable wrappers when using -proxy. Patch from Jan Jezabek ................ r10504 | bhy | 2008-05-28 18:27:48 +0100 (Wed, 28 May 2008) | 2 lines Fixed SF #1971977: typo in pycontainer.swg (related to -extranative option) ................ r10506 | wsfulton | 2008-05-29 01:45:28 +0100 (Thu, 29 May 2008) | 1 line Fix variable wrappers when using -noproxy ................ r10508 | bhy | 2008-05-30 14:53:33 +0100 (Fri, 30 May 2008) | 1 line Fixed SF #1976978, apply the macros for primitive types to std::wstring ................ r10511 | olly | 2008-05-30 17:11:27 +0100 (Fri, 30 May 2008) | 4 lines Fix typo in handling of /*@SWIG[...]*/ comments in the scanner. This just meant we were only actually looking for /*@SWI at the start of the comment, so was pretty harmless in practice. ................ r10515 | wsfulton | 2008-06-02 21:10:40 +0100 (Mon, 02 Jun 2008) | 1 line Fix samename testcase for c# and java ................ r10516 | wsfulton | 2008-06-02 21:15:39 +0100 (Mon, 02 Jun 2008) | 1 line Fix enums when using -noproxy ................ r10518 | bhy | 2008-06-07 12:20:07 +0100 (Sat, 07 Jun 2008) | 4 lines Added a test case for keyword renaming. Now it works for Python in SWIG's -c++ mode, but in C mode it doesn't work! (you can try with make keyword_rename.ctest) ................ r10519 | bhy | 2008-06-07 14:40:51 +0100 (Sat, 07 Jun 2008) | 1 line fixed keyword_rename.ctest tese case, caused by a mistake in Swig/naming.c ................ r10527 | mgossage | 2008-06-17 03:57:15 +0100 (Tue, 17 Jun 2008) | 1 line [lua] bugfix 1938142 (bool& and bool* support) ................ r10530 | wsfulton | 2008-06-19 21:02:13 +0100 (Thu, 19 Jun 2008) | 1 line Add R keyword support. Rename keywords for successful compilation of Java and C# code. More consistent keyword warnings across the different languages. ................ r10531 | wsfulton | 2008-06-19 22:15:48 +0100 (Thu, 19 Jun 2008) | 1 line add complete list of R reserved words ................ r10536 | wsfulton | 2008-06-21 12:35:33 +0100 (Sat, 21 Jun 2008) | 1 line better terminology for static types ................ r10537 | wsfulton | 2008-06-21 12:42:48 +0100 (Sat, 21 Jun 2008) | 1 line remove raise as keyword test- it conflicts with _raise in LIBCMT on windows ................ r10539 | wsfulton | 2008-06-21 16:21:29 +0100 (Sat, 21 Jun 2008) | 1 line Lua example warning removal fixes for vc++ ................ r10540 | wsfulton | 2008-06-21 16:23:02 +0100 (Sat, 21 Jun 2008) | 1 line Remove some vc++ /W4 warnings ................ r10541 | wsfulton | 2008-06-21 17:04:55 +0100 (Sat, 21 Jun 2008) | 1 line minor vc++ /W4 warning fixes ................ r10542 | wsfulton | 2008-06-21 20:07:51 +0100 (Sat, 21 Jun 2008) | 1 line 'byte' is already used in Ruby on windows, so use another keyword ................ r10543 | wsfulton | 2008-06-21 21:45:32 +0100 (Sat, 21 Jun 2008) | 1 line Fix crashing in the Ruby reject method in the STL wrappers ................ r10544 | wsfulton | 2008-06-21 21:48:28 +0100 (Sat, 21 Jun 2008) | 1 line Fix crashing in the Ruby reject method in the STL wrappers ................ r10545 | wsfulton | 2008-06-21 21:49:10 +0100 (Sat, 21 Jun 2008) | 1 line remove unnecessary variable int the char **STRING_ARRAY out typemap ................ r10546 | wsfulton | 2008-06-21 22:07:49 +0100 (Sat, 21 Jun 2008) | 1 line Fix Ruby C++ example dependencies in dsp files ................ r10547 | wsfulton | 2008-06-21 23:25:36 +0100 (Sat, 21 Jun 2008) | 1 line Fix unused parameter warnings in python when using gcc's -W -Wall options ................ r10548 | wsfulton | 2008-06-21 23:26:35 +0100 (Sat, 21 Jun 2008) | 1 line Fix virtual destructor ................ r10549 | wsfulton | 2008-06-22 00:25:20 +0100 (Sun, 22 Jun 2008) | 1 line various warning fixes ................ r10550 | wsfulton | 2008-06-22 01:09:11 +0100 (Sun, 22 Jun 2008) | 1 line Another fix for the JVM hanging on exit problem when using directors ................ r10551 | wsfulton | 2008-06-22 01:09:51 +0100 (Sun, 22 Jun 2008) | 1 line documentation sections update ................ r10552 | wsfulton | 2008-06-22 01:18:10 +0100 (Sun, 22 Jun 2008) | 1 line more docs on defining macros for the thread hanging problem ................ r10558 | wsfulton | 2008-06-22 22:30:20 +0100 (Sun, 22 Jun 2008) | 1 line fix unused parms in last commit for C code ................ r10559 | wsfulton | 2008-06-22 23:12:43 +0100 (Sun, 22 Jun 2008) | 1 line Suppress unused methods warning for VC++ ................ r10560 | wsfulton | 2008-06-23 21:26:07 +0100 (Mon, 23 Jun 2008) | 1 line fix partialcheck-test-suite and parallel make for r, chicken, tcl and php ................ r10561 | wsfulton | 2008-06-23 21:39:41 +0100 (Mon, 23 Jun 2008) | 1 line correct message display when running the partialcheck-test-suite make target ................ r10562 | wsfulton | 2008-06-23 22:14:53 +0100 (Mon, 23 Jun 2008) | 1 line fix typo ................ r10563 | olly | 2008-06-23 22:23:54 +0100 (Mon, 23 Jun 2008) | 3 lines Fix bad use of Python API (untested, since I can't even compile this code on x86-64!) ................ r10564 | olly | 2008-06-23 23:58:03 +0100 (Mon, 23 Jun 2008) | 3 lines [PHP] Fix segfault when wrapping a non-class function marked with %newobject (testcase char_strings). ................ r10565 | olly | 2008-06-24 01:27:34 +0100 (Tue, 24 Jun 2008) | 3 lines [PHP] Fix assertion failure when handling %typemap(in,numinputs=0) (testcase ignore_parameter). ................ r10566 | olly | 2008-06-24 01:33:08 +0100 (Tue, 24 Jun 2008) | 2 lines [PHP] Fix typemap_namespace.i to not try to copy a non-existent typemap. ................ r10567 | olly | 2008-06-24 01:41:07 +0100 (Tue, 24 Jun 2008) | 3 lines Clean up dead and unused code in SwigToPhpType(), and rename to GetShadowReturnType(). ................ r10568 | olly | 2008-06-24 01:42:29 +0100 (Tue, 24 Jun 2008) | 2 lines Fix cosmetic typo in string constant. ................ r10574 | wsfulton | 2008-06-24 21:10:28 +0100 (Tue, 24 Jun 2008) | 1 line zap last entry ................ r10575 | wsfulton | 2008-06-24 21:11:46 +0100 (Tue, 24 Jun 2008) | 1 line variable name changes to remove php keywords ................ r10576 | wsfulton | 2008-06-24 21:12:08 +0100 (Tue, 24 Jun 2008) | 1 line variable name hiding fix ................ r10577 | wsfulton | 2008-06-24 21:12:43 +0100 (Tue, 24 Jun 2008) | 1 line More info about numobjects added ................ r10578 | wsfulton | 2008-06-24 21:13:41 +0100 (Tue, 24 Jun 2008) | 1 line update for 1.3.36 release ................ r10579 | wsfulton | 2008-06-24 22:48:46 +0100 (Tue, 24 Jun 2008) | 1 line remove deprecated -c commandline option (runtime library generation) ................ r10580 | wsfulton | 2008-06-24 22:53:12 +0100 (Tue, 24 Jun 2008) | 1 line correct comment about deprecated option ................ r10582 | wsfulton | 2008-06-25 00:00:27 +0100 (Wed, 25 Jun 2008) | 1 line use rsync and ssh to upload releases to SourceForge as ftp no longer works ................ r10584 | wsfulton | 2008-06-25 00:24:48 +0100 (Wed, 25 Jun 2008) | 1 line correction for 1.3.36 ................ r10588 | wsfulton | 2008-06-25 01:16:04 +0100 (Wed, 25 Jun 2008) | 1 line section update ................ r10589 | wsfulton | 2008-06-25 01:16:40 +0100 (Wed, 25 Jun 2008) | 1 line bump version to 1.3.37 ................ r10594 | wsfulton | 2008-06-26 19:33:06 +0100 (Thu, 26 Jun 2008) | 1 line correct typo in first entry about %fragment ................ r10607 | wsfulton | 2008-06-29 01:19:05 +0100 (Sun, 29 Jun 2008) | 1 line fix some potential null pointer usage as reported by CoveriCoverity Prevent ................ r10608 | wsfulton | 2008-06-29 01:50:27 +0100 (Sun, 29 Jun 2008) | 1 line fix potential null pointer usage as reported by Coverity Prevent ................ r10609 | wsfulton | 2008-06-29 10:57:41 +0100 (Sun, 29 Jun 2008) | 1 line make life easier for svn status updates as everyone has different autotool versions installed - use svn:ignore on config.sub and config.guess ................ r10610 | wsfulton | 2008-06-29 11:08:14 +0100 (Sun, 29 Jun 2008) | 1 line make life easier for svn status updates as everyone has different autotool versions installed - use svn:ignore on config.sub and config.guess ................ r10616 | talby | 2008-07-01 00:41:27 +0100 (Tue, 01 Jul 2008) | 2 lines Hopefully this provides more portable values for Infinity and NaN in Perl. ................ r10621 | wsfulton | 2008-07-01 23:02:14 +0100 (Tue, 01 Jul 2008) | 1 line update old commandline option ................ r10624 | olly | 2008-07-02 04:17:46 +0100 (Wed, 02 Jul 2008) | 5 lines [Python] Import the C extension differently for Python 2.6 and later so that an implicit relative import doesn't produce a deprecation warning for 2.6 and a failure for 2.7 and later. Patch from Richard Boulton in SF#2008229. ................ r10625 | bhy | 2008-07-02 05:56:11 +0100 (Wed, 02 Jul 2008) | 1 line fix the relative import patch by try both relative and absolute import ................ r10626 | olly | 2008-07-02 06:55:18 +0100 (Wed, 02 Jul 2008) | 4 lines [PHP4] Support for PHP4 has been removed. The PHP developers are no longer making new PHP4 releases, and won't even be patching critical security issues after 2008-08-08. ................ r10627 | bhy | 2008-07-02 07:06:56 +0100 (Wed, 02 Jul 2008) | 1 line fix the previous commit -- new approach using imp module ................ r10628 | bhy | 2008-07-02 07:29:15 +0100 (Wed, 02 Jul 2008) | 1 line minor fix on relative import: close fp if exception occured during imp.find_module ................ r10629 | bhy | 2008-07-02 08:08:00 +0100 (Wed, 02 Jul 2008) | 1 line reconstruct the relative import, now the generated code looks better ................ r10633 | olly | 2008-07-03 01:09:56 +0100 (Thu, 03 Jul 2008) | 9 lines WARN_* constants are user visible, so keep existing WARN_PHP4_* for backward compatibility, but add preferred forms WARN_PHP_* and use these ourselves. Rename Lib/php4 to Lib/php, Source/Modules/php4.cxx to Source/Modules/php.cxx. Add typemaps for const reference so Examples/test-suite/apply_signed_char.i works. ................ r10634 | olly | 2008-07-03 01:12:58 +0100 (Thu, 03 Jul 2008) | 2 lines Remove file added in error. ................ r10635 | olly | 2008-07-03 01:37:38 +0100 (Thu, 03 Jul 2008) | 2 lines Rename php4*.swg to php*.swg. ................ r10636 | olly | 2008-07-03 02:13:51 +0100 (Thu, 03 Jul 2008) | 2 lines Update wrt PHP4. ................ r10637 | olly | 2008-07-03 03:32:11 +0100 (Thu, 03 Jul 2008) | 4 lines [PHP] The deprecated command line option "-phpfull" has been removed. We recommend building your extension as a dynamically loadable module. ................ r10638 | olly | 2008-07-03 03:32:41 +0100 (Thu, 03 Jul 2008) | 2 lines Fix version number ................ r10639 | olly | 2008-07-03 07:04:24 +0100 (Thu, 03 Jul 2008) | 2 lines Make t_output_helper() static. ................ r10640 | olly | 2008-07-03 07:05:34 +0100 (Thu, 03 Jul 2008) | 2 lines Make testcase li_typemaps work for PHP. ................ r10641 | olly | 2008-07-03 10:12:16 +0100 (Thu, 03 Jul 2008) | 2 lines Fix check::classname() to compare case-insensitively and not try to interpolate objects into strings. ................ r10643 | olly | 2008-07-03 23:00:01 +0100 (Thu, 03 Jul 2008) | 4 lines The operator& trick in allowexcept.i doesn't work for SWIG/PHP because the generated code takes the address of the variable in the code in the "vinit" section. So comment out the private operator& for PHP. ................ r10647 | olly | 2008-07-04 00:55:33 +0100 (Fri, 04 Jul 2008) | 2 lines [PHP] The SWIG cdata.i library module is now supported. ................ r10649 | olly | 2008-07-04 02:02:22 +0100 (Fri, 04 Jul 2008) | 4 lines [PHP] The deprecated command line option "-make" has been removed. Searches on Google codesearch suggest that nobody is using it now anyway. ................ r10650 | olly | 2008-07-04 02:22:11 +0100 (Fri, 04 Jul 2008) | 4 lines [PHP] For std_vector.i and std_map.i, rename empty() to is_empty() since "empty" is a PHP reserved word. Based of patch from Mark Klein in SF#1943417. ................ r10662 | wsfulton | 2008-07-14 22:09:23 +0100 (Mon, 14 Jul 2008) | 1 line Fix director typemaps for pointers so that NULL pointers are correctly marshalled to C#/Java null in director methods ................ r10672 | olly | 2008-07-17 02:17:08 +0100 (Thu, 17 Jul 2008) | 2 lines Fix a typo; improve wording. ................ r10676 | wsfulton | 2008-07-17 22:05:49 +0100 (Thu, 17 Jul 2008) | 1 line SF #2019156 Configuring with --without-octave or --without-alllang did not disable octave. ................ r10677 | wsfulton | 2008-07-17 22:08:22 +0100 (Thu, 17 Jul 2008) | 1 line tidy output after detecting X11 headers ................ r10682 | wsfulton | 2008-07-19 19:08:06 +0100 (Sat, 19 Jul 2008) | 1 line a bit more on pgcpp ................ r10683 | wsfulton | 2008-07-19 23:45:54 +0100 (Sat, 19 Jul 2008) | 1 line Fix building of Tcl examples/test-suite on Mac OSX ................ r10714 | olly | 2008-07-27 13:51:16 +0100 (Sun, 27 Jul 2008) | 2 lines Fix "can can" typo in docs (SF#2026756) ................ r10726 | wuzzeb | 2008-08-02 09:28:02 +0100 (Sat, 02 Aug 2008) | 1 line Commit patch 2019314 ................ r10727 | wuzzeb | 2008-08-02 09:49:43 +0100 (Sat, 02 Aug 2008) | 1 line add assert.h to fix chicken build of external runtime (ext_test testsuite) ................ r10738 | talby | 2008-08-07 07:28:13 +0100 (Thu, 07 Aug 2008) | 2 lines hoist globals to local scope where trival. ................ r10743 | talby | 2008-08-08 04:10:55 +0100 (Fri, 08 Aug 2008) | 2 lines initial steps to clean up perl5 class methods (primarily constructors). ................ r10747 | talby | 2008-08-09 05:08:26 +0100 (Sat, 09 Aug 2008) | 2 lines moves perl space constructor fixups into wrapper code. ................ r10749 | talby | 2008-08-10 00:57:55 +0100 (Sun, 10 Aug 2008) | 2 lines usage_func() fix + CHANGES.current entry to explain my past few commits. ................ r10794 | talby | 2008-08-19 08:09:29 +0100 (Tue, 19 Aug 2008) | 3 lines rollback 10737:10749, this work is better left on a branch until it is in support a significant feature enhancement. ................ r10801 | drjoe | 2008-08-31 17:07:43 +0100 (Sun, 31 Aug 2008) | 2 lines change Rf_warning to warning. Looks like a typo ................ r10802 | wsfulton | 2008-09-01 20:59:23 +0100 (Mon, 01 Sep 2008) | 1 line Fix ruby detection problem breaking configure ................ r10803 | wsfulton | 2008-09-01 21:00:28 +0100 (Mon, 01 Sep 2008) | 1 line Fix another perl global namespace pollution ................ r10804 | wsfulton | 2008-09-01 21:32:53 +0100 (Mon, 01 Sep 2008) | 1 line Fix array bounds checking in C# std::vector wrappers ................ r10805 | wsfulton | 2008-09-01 21:34:49 +0100 (Mon, 01 Sep 2008) | 1 line fix runtime problem in Ruby std_vector example ................ r10806 | wsfulton | 2008-09-01 21:42:40 +0100 (Mon, 01 Sep 2008) | 1 line Fix portability problem using /dev/null ................ r10807 | wsfulton | 2008-09-01 22:46:41 +0100 (Mon, 01 Sep 2008) | 1 line patch #2079381 submitted by Boris Smilga - constant exprs put into no-eval context in DEFCENUM ................ r10808 | wsfulton | 2008-09-02 21:56:52 +0100 (Tue, 02 Sep 2008) | 1 line Add new terminator attribute for the csin typemap for C# ................ r10809 | wsfulton | 2008-09-03 00:01:37 +0100 (Wed, 03 Sep 2008) | 1 line Fix #1988296 - Multiple module director linking issue ................ r10827 | richardb | 2008-09-10 11:08:21 +0100 (Wed, 10 Sep 2008) | 6 lines [Python] Commit patch #2089149: Director exception handling mangles returned exception. Exceptions raised by Python code in directors are now passed through to the caller without change. Also, remove the ": " prefix which used to be added to other director exceptions (eg, those due to incorrect return types). ................ r10828 | bhy | 2008-09-10 11:45:33 +0100 (Wed, 10 Sep 2008) | 3 lines Initialized merge tracking via "svnmerge" with revisions "1-10827" from https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-bhy ................ r10829 | bhy | 2008-09-10 12:04:09 +0100 (Wed, 10 Sep 2008) | 4 lines Removed merge tracking for "svnmerge" for https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-bhy (Undo the init due to user error) ................ r10830 | bhy | 2008-09-10 12:08:16 +0100 (Wed, 10 Sep 2008) | 3 lines Initialized merge tracking via "svnmerge" with revisions "1-10403" from https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-bhy ................ r10831 | bhy | 2008-09-10 12:51:12 +0100 (Wed, 10 Sep 2008) | 11 lines (Still trying to set right properity to get svnmerge work...) Recorded merge of revisions 10404 via svnmerge from https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-bhy ........ r10404 | bhy | 2008-05-01 08:35:49 +0800 (Thu, 01 May 2008) | 5 lines Start of gsoc2008-bhy branch. This is a branch for Haoyu Bai's Python 3.0 backend project. Some file already modified since a little of work already done when starting the branch. ........ ................ r10834 | bhy | 2008-09-11 18:18:07 +0100 (Thu, 11 Sep 2008) | 8 lines Merged the Python 3.0 support branch. The merging progress is not so smooth, so hope this commit won't make anything broken. This is the (incomplemete) log produced by svnmerge.py: Merged revisions 10405-10409,10420-10422,10426,10438,10445,10451,10454-10465,10467,10473-10475,10485,10488-10489,10493-10495,10497,10509-10510,10513-10514,10517,10520,10525,10528-10529,10533-10535,10554-10557,10570,10573,10593,10614,10666-10669,10673,10678,10687,10690,10704-10706,10731,10744,10750-10752,10755,10759,10770,10775-10776,10813,10819 via svnmerge from https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-bhy ................ git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-cherylfoil@10837 626c5289-ae23-0410-ae9c-e8d60b6d4f22
875 lines
22 KiB
HTML
875 lines
22 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<!-- Hand crafted HTML -->
|
|
<html>
|
|
<head>
|
|
<title>SWIG and PHP</title>
|
|
<link rel="stylesheet" type="text/css" href="style.css">
|
|
</head>
|
|
|
|
<body bgcolor="#ffffff">
|
|
<H1><a name="Php"></a>28 SWIG and PHP</H1>
|
|
<!-- INDEX -->
|
|
<div class="sectiontoc">
|
|
<ul>
|
|
<li><a href="#Php_nn1">Generating PHP Extensions</a>
|
|
<ul>
|
|
<li><a href="#Php_nn1_1">Building a loadable extension</a>
|
|
<li><a href="#Php_nn1_2">Building extensions into PHP</a>
|
|
<li><a href="#Php_nn1_3">Using PHP Extensions</a>
|
|
</ul>
|
|
<li><a href="#Php_nn2">Basic PHP interface</a>
|
|
<ul>
|
|
<li><a href="#Php_nn2_1">Constants</a>
|
|
<li><a href="#Php_nn2_2">Global Variables</a>
|
|
<li><a href="#Php_nn2_3">Functions</a>
|
|
<li><a href="#Php_nn2_4">Overloading</a>
|
|
<li><a href="#Php_nn2_5">Pointers and References</a>
|
|
<li><a href="#Php_nn2_6">Structures and C++ classes</a>
|
|
<ul>
|
|
<li><a href="#Php_nn2_6_1">Using <tt>-noproxy</tt></a>
|
|
<li><a href="#Php_nn2_6_2">Constructors and Destructors</a>
|
|
<li><a href="#Php_nn2_6_3">Static Member Variables</a>
|
|
<li><a href="#Php_nn2_6_4">Static Member Functions</a>
|
|
</ul>
|
|
<li><a href="#Php_nn2_7">PHP Pragmas, Startup and Shutdown code</a>
|
|
</ul>
|
|
</ul>
|
|
</div>
|
|
<!-- INDEX -->
|
|
|
|
|
|
|
|
<p>
|
|
<b>Caution: This chapter (and module!) is still under construction</b>
|
|
</p>
|
|
|
|
<p>
|
|
SWIG supports generating wrappers for PHP5. Support for PHP4 has been removed
|
|
as of SWIG 1.3.37. The PHP developers are no longer making new PHP4 releases,
|
|
and won't even be patching critical security issues after 2008-08-08, so it
|
|
doesn't make much sense for SWIG to continue to support PHP4 at this point.
|
|
If you need to continue to use PHP4, stick with SWIG 1.3.36.
|
|
</p>
|
|
|
|
<p>
|
|
In this chapter, we discuss SWIG's support of PHP. The PHP module
|
|
was extensively rewritten in release 1.3.26, and support for generating
|
|
OO wrappers for PHP5 was added in 1.3.30. The PHP module works fairly
|
|
well, but currently does not implement all the
|
|
features available in some of the other languages.
|
|
</p>
|
|
|
|
<p>
|
|
In order to use this module, you will need to have a copy of the PHP5
|
|
include files to compile the SWIG generated files. If you installed
|
|
PHP from a binary package, you may need to install a "php-dev" or "php-devel"
|
|
package for these to be installed. You can find out where these files are
|
|
by running <tt>php-config --includes</tt>. To use the built PHP module you
|
|
will need either the php binary or the Apache php module. If you want to build
|
|
your extension into php directly, you will need the complete PHP source tree
|
|
available.
|
|
</p>
|
|
|
|
<H2><a name="Php_nn1"></a>28.1 Generating PHP Extensions</H2>
|
|
|
|
|
|
<p>
|
|
To build a PHP extension, run swig using the <tt>-php</tt> option as
|
|
follows:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
swig -php example.i
|
|
</pre></div>
|
|
|
|
<p>
|
|
This will produce 3 files example_wrap.c, php_example.h and
|
|
example.php. The first file, <tt>example_wrap.c</tt> contains all of
|
|
the C code needed to build a PHP extension. The second file,
|
|
<tt>php_example.h</tt> contains the header information needed if
|
|
you wish to statically link the extension into the php interpreter.
|
|
The third file,
|
|
<tt>example.php</tt> can be included by PHP scripts. It attempts to
|
|
dynamically load the extension and contains extra php code specified
|
|
in the interface file. If wrapping C++ code with PHP classes, it will
|
|
also contain PHP5 class wrappers.
|
|
</p>
|
|
|
|
<p>
|
|
Swig can generate PHP extensions from C++ libraries as well when
|
|
given the <tt>-c++</tt> option. The support for C++ is discussed in
|
|
more detail in <a href="#Php_nn2_6">section 27.2.6</a>.
|
|
</p>
|
|
|
|
<p>
|
|
The usual (and recommended) way is to build the extension as a separate
|
|
dynamically loaded module (which is supported by all modern operating
|
|
systems). You can then specify that this be loaded
|
|
automatically in <tt>php.ini</tt> or load it explicitly for any script which
|
|
needs it.
|
|
</p>
|
|
|
|
<p>
|
|
It is also possible to rebuild PHP from source so that your module is
|
|
statically linked into the php executable/library. This is a lot more
|
|
work, and also requires a full rebuild of PHP to update your module,
|
|
and it doesn't play nicely with package system. We don't recommend
|
|
this approach, or provide explicit support for it.
|
|
</p>
|
|
|
|
<H3><a name="Php_nn1_1"></a>28.1.1 Building a loadable extension</H3>
|
|
|
|
<p>
|
|
To build your module as a dynamically loadable extension, use compilation
|
|
commands like these (if you aren't using GCC, the commands will be different,
|
|
and there may be some variation between platforms - these commands should at
|
|
least work for Linux though):
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
gcc `php-config --includes` -fpic -c example_wrap.c
|
|
gcc -shared example_wrap.o -o example.so
|
|
</pre></div>
|
|
|
|
<H3><a name="Php_nn1_3"></a>28.1.3 Using PHP Extensions</H3>
|
|
|
|
<p>
|
|
To test the extension from a PHP script, you need to load it first. You
|
|
can load it for every script by adding this line the <tt>[PHP]</tt> section of
|
|
<tt>php.ini</tt>:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
extension=/path/to/modulename.so
|
|
</pre></div>
|
|
|
|
<p>
|
|
Alternatively, you can load it explicitly only for scripts which need it
|
|
by adding this line:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
dl("/path/to/modulename.so"); // Load the module
|
|
</pre></div>
|
|
|
|
<p>
|
|
to the start of each PHP file. SWIG also generates a php module, which
|
|
attempts to do the <tt>dl()</tt> call for you:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
include("example.php");
|
|
</pre></div>
|
|
|
|
<H2><a name="Php_nn2"></a>28.2 Basic PHP interface</H2>
|
|
|
|
|
|
<p>
|
|
It is important to understand that PHP uses a single global namespace
|
|
into which all symbols from extension modules are loaded. It is quite
|
|
possible for names of symbols in one extension module to clash with
|
|
other symbols unless care is taken to <tt>%rename</tt> them.
|
|
</p>
|
|
|
|
<H3><a name="Php_nn2_1"></a>28.2.1 Constants</H3>
|
|
|
|
|
|
<p>
|
|
These work in much the same way as in C/C++, constants can be defined
|
|
by using either the normal C pre-processor declarations, or the
|
|
<tt>%constant</tt> SWIG directive. These will then be available from
|
|
your PHP script as a PHP constant, (i.e. no dollar sign is needed to
|
|
access them.) For example, with a swig interface file like this,
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example
|
|
|
|
#define PI 3.14159
|
|
|
|
%constant int E = 2.71828
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
you can access the constants in your php script like this,
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
include("example.php");
|
|
|
|
echo "PI = " . PI . "\n";
|
|
|
|
echo "E = " . E . "\n";
|
|
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
There are two peculiarities with using constants in PHP. The first is that
|
|
if you try to use an undeclared constant, it will evaluate to a string
|
|
set to the constant's name. For example,
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example
|
|
|
|
#define EASY_TO_MISPELL 0
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
accessed incorrectly in PHP,
|
|
</p>
|
|
|
|
<div class="code">
|
|
<pre>
|
|
include("example.php");
|
|
|
|
if(EASY_TO_MISPEL) {
|
|
....
|
|
} else {
|
|
....
|
|
}
|
|
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
will issue a warning about the undeclared constant, but will then
|
|
evaluate it and turn it into a string ('EASY_TO_MISPEL'), which
|
|
evaluates to true, rather than the value of the constant which would
|
|
be false. This is a feature!
|
|
</p>
|
|
|
|
<p>
|
|
The second 'feature' is that although constants are case sensitive (by
|
|
default), you cannot declare a constant twice with alternative
|
|
cases. E.g.,
|
|
</p>
|
|
|
|
<div class="code">
|
|
<pre>
|
|
%module example
|
|
|
|
#define TEST Hello
|
|
#define Test World
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
accessed from PHP,
|
|
</p>
|
|
|
|
<div class="code">
|
|
<pre>
|
|
include("example.php");
|
|
|
|
echo TEST, Test;
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
will output "Hello Test" rather than "Hello World". This is because
|
|
internally, all constants are stored in a hash table by their lower
|
|
case name, so 'TEST' and 'Test' will map to the same hash element
|
|
('Test'). But, because we declared them case sensitive, the Zend
|
|
engine will test if the case matches with the case the constant was
|
|
declared with first.
|
|
</p>
|
|
|
|
<p>
|
|
So, in the example above, the TEST constant was declared first, and
|
|
will be stored under the hash element 'test'. The 'Test' constant will
|
|
also map to the same hash element 'test', but will not overwrite
|
|
it. When called from the script, the TEST constant will again be
|
|
mapped to the hash element 'test' so the constant will be
|
|
retrieved. The case will then be checked, and will match up, so the
|
|
value ('Hello') will be returned. When 'Test' is evaluated, it will
|
|
also map to the same hash element 'test'. The same constant will be
|
|
retrieved, this time though the case check will fail as 'Test' !=
|
|
'TEST'. So PHP will assume that Test is a undeclared constant, and as
|
|
explained above, will return it as a string set to the constant name
|
|
('Test'). Hence the script above will print 'Hello Test'. If they were
|
|
declared non-case sensitive, the output would be 'Hello Hello', as
|
|
both point to the same value, without the case test taking place. (
|
|
Apologies, this paragraph needs rewriting to make some sense. )
|
|
</p>
|
|
|
|
<H3><a name="Php_nn2_2"></a>28.2.2 Global Variables</H3>
|
|
|
|
|
|
<p>
|
|
Because PHP does not provide a mechanism to intercept access and
|
|
assignment of global variables, global variables are supported through
|
|
the use of automatically generated accessor functions.
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example;
|
|
|
|
%inline %{
|
|
double seki = 2;
|
|
void print_seki() {
|
|
zend_printf("seki is now %f\n",seki);
|
|
}
|
|
%}
|
|
</pre></div>
|
|
|
|
<p>
|
|
is accessed as follows:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
include("example.php");
|
|
print seki_get();
|
|
seki_set( seki_get() * 2); # The C variable is now 4.
|
|
print seki_get();
|
|
</pre></div>
|
|
|
|
<p>
|
|
SWIG supports global variables of all C datatypes including pointers
|
|
and complex objects. Additional types can be supported by using the
|
|
<tt>varinit</tt> typemap.
|
|
</p>
|
|
|
|
<p>
|
|
SWIG honors the <tt>%immutable</tt> modifier by not generating code
|
|
for the <tt>_set</tt> method. This provides read-only access to the
|
|
variable from the php script. Attempting to access the <tt>_set</tt>
|
|
method will result in a php fatal error because the function is
|
|
undefined.
|
|
</p>
|
|
|
|
<p>
|
|
At this time SWIG does not support custom accessor methods.
|
|
</p>
|
|
|
|
<H3><a name="Php_nn2_3"></a>28.2.3 Functions</H3>
|
|
|
|
|
|
<p>
|
|
C functions are converted into PHP functions. Default/optional arguments are
|
|
also allowed. An interface file like this :
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example
|
|
int foo(int a);
|
|
double bar(double, double b = 3.0);
|
|
...
|
|
</pre></div>
|
|
|
|
<p>
|
|
Will be accessed in PHP like this :
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
include("example.php");
|
|
$a = foo(2);
|
|
$b = bar(3.5, -1.5);
|
|
$c = bar(3.5); # Use default argument for 2nd parameter
|
|
|
|
</pre></div>
|
|
|
|
<!-- This isn't correct for 1.3.30 and needs rewriting to reflect reality
|
|
<p>
|
|
Because PHP is a dynamically typed language, the default typemaps
|
|
used for simple types will attempt to coerce the arguments into the appropriate type. That is the following invocations are equivalent:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
$a = foo(2);
|
|
$a = foo("2");
|
|
$a = foo(2.0);
|
|
</pre></div>
|
|
|
|
<p>
|
|
Functions are invoked using pass by value semantics like all of PHP.
|
|
This means the conversion which automatically takes place when
|
|
invoking a swig wrapped method does not change the native type of the
|
|
argument variable.
|
|
</p>
|
|
<div class="code"><pre>
|
|
$s = "2 A string representing two";
|
|
$a = foo($s); # invokes 'foo(2)';
|
|
print $s; # The value of $s was not changed.
|
|
</pre></div>
|
|
-->
|
|
|
|
|
|
<H3><a name="Php_nn2_4"></a>28.2.4 Overloading</H3>
|
|
|
|
|
|
<p>
|
|
Although PHP does not support overloading functions natively, swig
|
|
will generate dispatch functions which will use <tt>%typecheck</tt>
|
|
typemaps to allow overloading. This dispatch function's operation and
|
|
precedence is described in <a
|
|
href="TypemapsSWIGPlus.html#SWIGPlus_overloaded_methods">Wrapping
|
|
Overloaded Functions and Methods</a>.
|
|
</p>
|
|
|
|
<!-- This isn't correct for 1.3.30 and needs rewriting to reflect reality
|
|
<p>
|
|
Because PHP4 is a dynamically typed language, simple values can be
|
|
silently converted from one type to another. For example, integers,
|
|
doubles and strings silently convert to each other depending on
|
|
context. This situation make overloading slightly problematic because
|
|
given the following function:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
void doit( int i );
|
|
void doit( double i );
|
|
</pre></div>
|
|
|
|
<p>
|
|
it is questionable which to invoke when <tt>doit("2");</tt> is used in
|
|
PHP. The string <tt>"2"</tt> simultaneously represents the integer
|
|
<tt>2</tt> and the double <tt>2.0</tt>.
|
|
</p>
|
|
|
|
<p>
|
|
In order to provide the most natural experience to PHP programmers,
|
|
the default <tt>%typecheck</tt> implemented in <tt>php4.swg</tt>
|
|
allows any simple type (integer, double, string) in PHP to be used for
|
|
any simple C type (int, double, char *). The function selected then
|
|
depends only on the argument type precedence defined by SWIG.
|
|
</p>
|
|
|
|
<p>
|
|
It should be noted that <tt>SWIGTYPE</tt> references and pointers will
|
|
not be silently converted. So these two functions:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
void doit( const Vector & );
|
|
void doit( int i );
|
|
</pre></div>
|
|
|
|
<p>
|
|
Cause less confusion and <tt>doit("2");</tt> will invoke the function
|
|
taking the integer argument.
|
|
</p>
|
|
-->
|
|
|
|
<H3><a name="Php_nn2_5"></a>28.2.5 Pointers and References</H3>
|
|
|
|
|
|
<p>
|
|
Pointers to C/C++ objects are represented
|
|
as PHP resources, rather like MySQL connection handles.
|
|
</p>
|
|
|
|
<p>
|
|
There are multiple ways to wrap pointers to simple types. Given the
|
|
following C method:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
void add( int *in1, int *in2, int *result);
|
|
</pre></div>
|
|
|
|
<p>
|
|
One can include <b>cpointer.i</b> to generate PHP wrappers to <tt>int
|
|
*</tt>.
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example
|
|
%include cpointer.i
|
|
%pointer_functions(int,intp)
|
|
|
|
void add( int *in1, int *in2, int *result);
|
|
</pre></div>
|
|
|
|
<p>
|
|
This will result in the following usage in PHP:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
<?php
|
|
|
|
include("example.php");
|
|
|
|
$in1=copy_intp(3);
|
|
$in2=copy_intp(5);
|
|
$result=new_intp();
|
|
|
|
add( $in1, $in2, $result );
|
|
|
|
echo "The sum " . intp_value($in1) . " + " . intp_value($in2) . " = " . intp_value( $result) . "\n";
|
|
?>
|
|
</pre></div>
|
|
|
|
<p>
|
|
An alternative would be to use the include <b>typemaps.i</b> which
|
|
defines named typemaps for INPUT, OUTPUT and INOUT variables. One
|
|
needs to either <tt>%apply</tt> the appropriate typemap or adjust the
|
|
parameter names as appropriate.
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example
|
|
%include typemaps.i
|
|
|
|
void add( int *INPUT, int *INPUT, int *OUTPUT);
|
|
|
|
</pre></div>
|
|
|
|
<p>
|
|
This will result in the following usage in PHP:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
<?php
|
|
|
|
include("example.php");
|
|
|
|
$in1 = 3;
|
|
$in2 = 5;
|
|
$result= add($in1,$in2); # Note using variables for the input is unnecessary.
|
|
|
|
echo "The sum $in1 + $in2 = $result\n";
|
|
?>
|
|
</pre></div>
|
|
|
|
<p>
|
|
Because PHP has a native concept of reference, it may seem more natural
|
|
to the PHP developer to use references to pass pointers. To enable
|
|
this, one needs to include <b>phppointers.i</b> which defines the
|
|
named typemap REFERENCE.
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example
|
|
%include phppointers.i
|
|
|
|
void add( int *REF, int *REF, int *REF);
|
|
|
|
</pre></div>
|
|
|
|
<p>
|
|
This will result in the following usage in PHP:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
<?php
|
|
|
|
include("example.php");
|
|
|
|
$in1 = 3;
|
|
$in2 = 5;
|
|
$result = 0;
|
|
add(&$in1,&$in2,&$result);
|
|
|
|
echo "The sum $in1 + $in2 = $result\n";
|
|
?>
|
|
</pre></div>
|
|
|
|
<p>
|
|
It is important to note that a php variable which is NULL when passed
|
|
by reference would end up passing a NULL pointer into the function.
|
|
In PHP, an unassigned variable (i.e. where the first reference to the
|
|
variable is not an assignment) is
|
|
NULL. In the above example, if any of the three variables had not
|
|
been assigned, a NULL pointer would have been passed into
|
|
<tt>add</tt>. Depending on the implementation of the function, this
|
|
may or may not be a good thing.
|
|
</p>
|
|
|
|
<p>
|
|
We chose to allow passing NULL pointers into functions because that is
|
|
sometimes required in C libraries. A NULL pointer can be created in
|
|
PHP in a number of ways: by using <tt>unset</tt> on an existing
|
|
variable, or assigning <tt>NULL</tt> to a variable.
|
|
</p>
|
|
|
|
<H3><a name="Php_nn2_6"></a>28.2.6 Structures and C++ classes</H3>
|
|
|
|
|
|
<p>
|
|
SWIG defaults to wrapping C++ structs and classes with PHP classes
|
|
unless "-noproxy" is specified. For PHP5, a PHP wrapper
|
|
class is generated which calls a set of flat functions wrapping the C++ class.
|
|
</p>
|
|
|
|
<p>
|
|
This interface file
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module vector
|
|
|
|
class Vector {
|
|
public:
|
|
double x,y,z;
|
|
Vector();
|
|
~Vector();
|
|
double magnitude();
|
|
};
|
|
|
|
struct Complex {
|
|
double re, im;
|
|
};
|
|
</pre></div>
|
|
|
|
<p>
|
|
Would be used in the following way from PHP5:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
<?php
|
|
require "vector.php";
|
|
|
|
$v = new Vector();
|
|
$v->x = 3;
|
|
$v->y = 4;
|
|
$v->z = 5;
|
|
|
|
echo "Magnitude of ($v->x,$v->y,$v->z) = " . $v->magnitude() . "\n";
|
|
|
|
$v = NULL; # destructor called.
|
|
|
|
$c = new Complex();
|
|
|
|
$c->re = 0;
|
|
$c->im = 0;
|
|
|
|
# $c destructor called when $c goes out of scope.
|
|
?>
|
|
</pre></div>
|
|
|
|
<p>
|
|
Member variables and methods are accessed using the <tt>-></tt> operator.
|
|
</p>
|
|
|
|
<H4><a name="Php_nn2_6_1"></a>28.2.6.1 Using <tt>-noproxy</tt></H4>
|
|
|
|
|
|
<p>
|
|
The <tt>-noproxy</tt> option flattens the object structure and
|
|
generates collections of named functions (these are the functions
|
|
which the PHP5 class wrappers call). The above example results
|
|
in the following PHP functions:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
new_Vector();
|
|
Vector_x_set($obj,$d);
|
|
Vector_x_get($obj);
|
|
Vector_y_set($obj,$d);
|
|
Vector_y_get($obj);
|
|
Vector_z_set($obj,$d);
|
|
Vector_z_get($obj);
|
|
Vector_magnitude($obj);
|
|
new_Complex();
|
|
Complex_re_set($obj,$d);
|
|
Complex_re_get($obj);
|
|
Complex_im_set($obj,$d);
|
|
Complex_im_get($obj);
|
|
</pre></div>
|
|
|
|
<H4><a name="Php_nn2_6_2"></a>28.2.6.2 Constructors and Destructors</H4>
|
|
|
|
|
|
<p>
|
|
The constructor is called when <tt>new Object()</tt> (or
|
|
<tt>new_Object()</tt> if using <tt>-noproxy</tt>) is used to create an
|
|
instance of the object. If multiple constructors are defined for an
|
|
object, function overloading will be used to determine which
|
|
constructor to execute.
|
|
</p>
|
|
|
|
<p>
|
|
Because PHP uses reference counting to manage resources, simple
|
|
assignment of one variable to another such as:
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
$ref = $v;
|
|
</pre></div>
|
|
|
|
<p>
|
|
causes the symbol <tt>$ref</tt> to refer to the same underlying object
|
|
as <tt>$v</tt>. This does not result in a call to the C++ copy
|
|
constructor or copy assignment operator.
|
|
</p>
|
|
|
|
<p>
|
|
One can force execution of the copy constructor by using:
|
|
</p>
|
|
<div class="code"><pre>
|
|
$o_copy = new Object($o);
|
|
</pre></div>
|
|
|
|
<p>
|
|
Destructors are automatically called when all variables referencing
|
|
the instance are reassigned or go out of scope. The destructor is not
|
|
available to be called manually. To force a destructor to be called
|
|
the programmer can either reassign the variable or call
|
|
<tt>unset($v)</tt>
|
|
</p>
|
|
|
|
<H4><a name="Php_nn2_6_3"></a>28.2.6.3 Static Member Variables</H4>
|
|
|
|
|
|
<p>
|
|
Static member variables in C++ are not wrapped as such in PHP
|
|
as it does not appear to be possible to intercept accesses to such variables.
|
|
Therefore, static member variables are
|
|
wrapped using a class function with the same name, which
|
|
returns the current value of the class variable. For example
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example
|
|
|
|
class Ko {
|
|
static int threats;
|
|
};
|
|
|
|
</pre></div>
|
|
|
|
<p>
|
|
would be accessed in PHP as,
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
include("example.php");
|
|
|
|
echo "There has now been " . Ko::threats() . " threats\n";
|
|
|
|
</pre></div>
|
|
|
|
<p>
|
|
To set the static member variable, pass the value as the argument to the class
|
|
function, e.g.
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
|
|
Ko::threats(10);
|
|
|
|
echo "There has now been " . Ko::threats() . " threats\n";
|
|
|
|
</pre></div>
|
|
<H4><a name="Php_nn2_6_4"></a>28.2.6.4 Static Member Functions</H4>
|
|
|
|
|
|
<p>
|
|
Static member functions are supported in PHP using the
|
|
<tt>class::function()</tt> syntax. For example
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example
|
|
class Ko {
|
|
static void threats();
|
|
};
|
|
</pre></div>
|
|
|
|
would be executed in PHP as,
|
|
<div class="code"><pre>
|
|
include("example.php");
|
|
Ko::threats();
|
|
</pre></div>
|
|
|
|
|
|
<H3><a name="Php_nn2_7"></a>28.2.7 PHP Pragmas, Startup and Shutdown code</H3>
|
|
|
|
|
|
<p>
|
|
Note: Currently pragmas for PHP need to be specified using
|
|
<tt>%pragma(php4)</tt> but also apply for PHP5! This is just a historical
|
|
oddity because SWIG's PHP support predates PHP5.
|
|
</p>
|
|
|
|
<p>
|
|
To place PHP code in the generated "example.php" file one can use the
|
|
<b>code</b> pragma. The code is inserted after loading the shared
|
|
object.
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example
|
|
%pragma(php4) code="
|
|
# This code is inserted into example.php
|
|
echo \"example.php execution\\n\";
|
|
"
|
|
</pre></div>
|
|
|
|
<p>
|
|
Results in the following in "example.php"
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
# This code is inserted into example.php
|
|
echo "example.php execution\n";
|
|
</pre></div>
|
|
|
|
<p>
|
|
The <b>include</b> pragma is a short cut to add include statements to
|
|
the example.php file.
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example
|
|
%pragma(php4) code="
|
|
include \"include.php\";
|
|
"
|
|
%pragma(php) include="include.php" // equivalent.
|
|
</pre></div>
|
|
|
|
<p>
|
|
The <b>phpinfo</b> pragma inserts code in the
|
|
<tt>PHP_MINFO_FUNCTION</tt> which is called from PHP's
|
|
phpinfo() function.
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example;
|
|
%pragma(php4) phpinfo="
|
|
zend_printf("An example of PHP support through SWIG\n");
|
|
php_info_print_table_start();
|
|
php_info_print_table_header(2, \"Directive\", \"Value\");
|
|
php_info_print_table_row(2, \"Example support\", \"enabled\");
|
|
php_info_print_table_end();
|
|
"
|
|
</pre></div>
|
|
|
|
<p>
|
|
To insert code into the <tt>PHP_MINIT_FUNCTION</tt>, one can use
|
|
either <tt>%init</tt> or <tt>%minit</tt>.
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example;
|
|
%init {
|
|
zend_printf("Inserted into PHP_MINIT_FUNCTION\n");
|
|
}
|
|
%minit {
|
|
zend_printf("Inserted into PHP_MINIT_FUNCTION\n");
|
|
}
|
|
</pre></div>
|
|
|
|
<p>
|
|
To insert code into the <tt>PHP_MSHUTDOWN_FUNCTION</tt>, one can use
|
|
either <tt>%init</tt> or <tt>%minit</tt>.
|
|
</p>
|
|
|
|
<div class="code"><pre>
|
|
%module example;
|
|
%mshutdown {
|
|
zend_printf("Inserted into PHP_MSHUTDOWN_FUNCTION\n");
|
|
}
|
|
</pre></div>
|
|
|
|
<p>
|
|
The <tt>%rinit</tt> and <tt>%rshutdown</tt> statements insert code
|
|
into the request init and shutdown code respectively.
|
|
</p>
|
|
|
|
</body>
|
|
</html>
|