diff --git a/.gitignore b/.gitignore index 0006e6ef6..b51da0fdf 100644 --- a/.gitignore +++ b/.gitignore @@ -184,11 +184,8 @@ Examples/perl5/*/*.pm # PHP Examples/test-suite/php/php_*.h -Examples/test-suite/php/*.php -!Examples/test-suite/php/*runme.php -!Examples/test-suite/php/skel.php Examples/php/*/php_*.h -Examples/php/*/example.php +Examples/php/pragmas/example.php # Python # Based on https://github.com/github/gitignore/blob/master/Python.gitignore diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index e31802c02..254f05c52 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -84,16 +84,21 @@ swig -php7 example.i

-This will produce 3 files example_wrap.c, php_example.h and -example.php. The first file, example_wrap.c contains all of +This will produce 2 files: example_wrap.c and php_example.h. +The first file, example_wrap.c contains all of the C code needed to build a PHP extension. The second file, php_example.h contains the header information needed if you wish to statically link the extension into the php interpreter. -The third file, -example.php 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 PHP class wrappers. +

+ +

+If the interface file uses %pragma(php) include=... or +%pragma(php) code=... then SWIG will also generate a third file, +example.php to contain what these specify. In SWIG < 4.1.0, +this third file was always generated as it defined the PHP classes, etc +(but this is now done via C code in example_wrap.c) and also +contained code to dynamically load the extension (but this used the +PHP dl() function, which isn't recommended nowadays).

@@ -178,15 +183,6 @@ better to instead use extension in php.ini as described above.

-

-SWIG also generates a PHP module which defines PHP classes for the wrapped -API, which you'll need to load, for example: -

- -
-        include("example.php");
-
-

32.2 Basic PHP interface

@@ -224,12 +220,8 @@ you can access the constants in your PHP script like this,

-include("example.php");
-
 echo "PI = " . PI . "\n";
-
 echo "E = " . E . "\n";
-
 
@@ -261,8 +253,6 @@ accessed incorrectly in PHP,
-include("example.php");
-
 if(EASY_TO_MISPEL) {
   ...
 } else {
@@ -303,7 +293,6 @@ is accessed as follows:
 

-include("example.php");
 print seki_get();
 seki_set( seki_get() * 2); # The C variable is now 4.
 print seki_get();
@@ -349,7 +338,6 @@ Will be accessed in PHP like this :
 

-include("example.php");
 $a = foo(2);
 $b = bar(3.5, -1.5);
 $c = bar(3.5);  # Use default argument for 2nd parameter
@@ -474,8 +462,6 @@ This will result in the following usage in PHP:
 
 <?php
 
-include("example.php");
-
 $in1=copy_intp(3);
 $in2=copy_intp(5);
 $result=new_intp();
@@ -507,8 +493,6 @@ This will result in the following usage in PHP:
 
 <?php
 
-include("example.php");
-
 $in1 = 3;
 $in2 = 5;
 $result= add($in1, $in2);  # Note using variables for the input is unnecessary.
@@ -544,8 +528,6 @@ This will result in the following usage in PHP:
 
 <?php
 
-include("example.php");
-
 $in1 = 3;
 $in2 = 5;
 $result = 0;
@@ -609,7 +591,6 @@ Would be used in the following way from PHP:
 
 
 <?php
-  require "vector.php";
 
   $v = new Vector();
   $v->x = 3;
@@ -724,8 +705,6 @@ would be accessed in PHP as,
 

-include("example.php");
-
 echo "There have now been " . Ko::threats() . " threats\n";
 
 
@@ -759,7 +738,6 @@ class Ko { would be executed in PHP as,
-include("example.php");
 Ko::threats();
 
@@ -786,9 +764,8 @@ If there are multiple interfaces, just list them separated by commas.

-To place PHP code in the generated "example.php" file one can use the -code pragma. The code is inserted after loading the shared -object. +You can get SWIG to generate an "example.php" file by specifying +the code to put in it using the code pragma.

@@ -992,8 +969,6 @@ then at the PHP side you can define
 
 
-require("mymodule.php");
-
 class MyFoo extends Foo {
   function one() {
     print "one from php\n";
diff --git a/Examples/php/callback/runme.php b/Examples/php/callback/runme.php
index fe4cd8b95..e7093209c 100644
--- a/Examples/php/callback/runme.php
+++ b/Examples/php/callback/runme.php
@@ -2,8 +2,6 @@
 
 # This file illustrates the cross language polymorphism using directors.
 
-require("example.php");
-
 # Class, which overwrites Callback::run().
 
 class PhpCallback extends Callback {
diff --git a/Examples/php/class/runme.php b/Examples/php/class/runme.php
index 88b4cfc79..0f667695b 100644
--- a/Examples/php/class/runme.php
+++ b/Examples/php/class/runme.php
@@ -2,8 +2,6 @@
 
 # This example illustrates how member variables are wrapped.
 
-require("example.php");
-
 # ----- Object creation -----
 
 print "Creating some objects:\n";
diff --git a/Examples/php/constants/runme.php b/Examples/php/constants/runme.php
index ef923829d..e561626d8 100644
--- a/Examples/php/constants/runme.php
+++ b/Examples/php/constants/runme.php
@@ -1,7 +1,5 @@
 x = 1.0;
         $v->y = 2.0;
diff --git a/Examples/php/variables/runme.php b/Examples/php/variables/runme.php
index 126b54216..a14fede72 100644
--- a/Examples/php/variables/runme.php
+++ b/Examples/php/variables/runme.php
@@ -1,6 +1,5 @@
 foo(1), 0, "");
diff --git a/Examples/test-suite/php/php_iterator_runme.php b/Examples/test-suite/php/php_iterator_runme.php
index edaaf2bdc..76b4757fc 100644
--- a/Examples/test-suite/php/php_iterator_runme.php
+++ b/Examples/test-suite/php/php_iterator_runme.php
@@ -1,7 +1,6 @@
 getVersion(),"1.5==version(php_pragma)");
 
diff --git a/Examples/test-suite/php/pointer_reference_runme.php b/Examples/test-suite/php/pointer_reference_runme.php
index 3fa3c6a85..a8a511271 100644
--- a/Examples/test-suite/php/pointer_reference_runme.php
+++ b/Examples/test-suite/php/pointer_reference_runme.php
@@ -1,7 +1,6 @@
 value, 10, "pointer_reference::get() failed");
diff --git a/Examples/test-suite/php/prefix_runme.php b/Examples/test-suite/php/prefix_runme.php
index eaabcf32e..0f56b041d 100644
--- a/Examples/test-suite/php/prefix_runme.php
+++ b/Examples/test-suite/php/prefix_runme.php
@@ -1,7 +1,6 @@
  0 || Len(pragma_code) > 0) {
+      /* PHP module file */
+      String *php_filename = NewStringEmpty();
+      Printv(php_filename, SWIG_output_directory(), module, ".php", NIL);
+
+      File *f_phpcode = NewFile(php_filename, "w", SWIG_output_files());
+      if (!f_phpcode) {
+	FileErrorDisplay(php_filename);
+	SWIG_exit(EXIT_FAILURE);
+      }
+
+      Printf(f_phpcode, " 0) {
+	Printv(f_phpcode, pragma_incl, "\n", NIL);
+      }
+
+      if (Len(pragma_code) > 0) {
+	Printv(f_phpcode, pragma_code, "\n", NIL);
+      }
+
+      Delete(f_phpcode);
+      Delete(php_filename);
+    }
 
     return SWIG_OK;
   }