-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed the Php::include_once() call for PHP 8.1
- Loading branch information
1 parent
1d878ff
commit 009580d
Showing
6 changed files
with
146 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
; configuration for phpcpp module | ||
; priority=30 | ||
extension=includeonce.so | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
CPP = g++ | ||
RM = rm -f | ||
CPP_FLAGS = -Wall -c -I. -O2 -std=c++11 | ||
PHP_CONFIG = $(shell which php-config) | ||
LIBRARY_DIR = $(shell ${PHP_CONFIG} --extension-dir) | ||
PHP_CONFIG_DIR = $(shell ${PHP_CONFIG} --ini-dir) | ||
|
||
LD = g++ | ||
LD_FLAGS = -Wall -shared -O2 | ||
RESULT = includeonce.so | ||
|
||
PHPINIFILE = 30-includeonce.ini | ||
|
||
SOURCES = $(wildcard *.cpp) | ||
OBJECTS = $(SOURCES:%.cpp=%.o) | ||
|
||
all: ${OBJECTS} ${RESULT} | ||
|
||
${RESULT}: ${OBJECTS} | ||
${LD} ${LD_FLAGS} -o $@ ${OBJECTS} -lphpcpp | ||
|
||
clean: | ||
${RM} *.obj *~* ${OBJECTS} ${RESULT} | ||
|
||
${OBJECTS}: | ||
${CPP} ${CPP_FLAGS} -fpic -o $@ ${@:%.o=%.cpp} | ||
|
||
install: | ||
cp -f ${RESULT} ${LIBRARY_DIR}/ | ||
cp -f ${PHPINIFILE} ${PHP_CONFIG_DIR}/ | ||
|
||
uninstall: | ||
rm ${LIBRARY_DIR}/${RESULT} | ||
rm ${PHP_CONFIG_DIR}/${PHPINIFILE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* Class.php | ||
* | ||
* Empty class, we just try to double-include this file to run into a | ||
* "class already defined" error | ||
* | ||
* @author Emiel Bruijntjes <[email protected]> | ||
* @copyright 2024 Copernica BV | ||
*/ | ||
|
||
/** | ||
* Include ourselves (should do nothing) | ||
*/ | ||
include_once(__FILE__); | ||
my_include_once(__FILE__); | ||
|
||
/** | ||
* Class definition | ||
*/ | ||
class SillyClass {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* callphpfunction.cpp | ||
* @author Jasper van Eck<[email protected]> | ||
* | ||
* An example file to show the working of a php function call in C++. | ||
*/ | ||
|
||
/** | ||
* Libraries used. | ||
*/ | ||
#include <iostream> | ||
#include <phpcpp.h> | ||
|
||
/** | ||
* Namespace to use | ||
*/ | ||
using namespace std; | ||
|
||
/** | ||
* Function to test the Php::include_once() call | ||
* @param ¶ms | ||
*/ | ||
void my_include_once(Php::Parameters ¶ms) | ||
{ | ||
// the string | ||
Php::Value path = params[0]; | ||
|
||
// do the call | ||
Php::include_once(path.stringValue()); | ||
} | ||
|
||
|
||
// Symbols are exported according to the "C" language | ||
extern "C" | ||
{ | ||
// export the "get_module" function that will be called by the Zend engine | ||
PHPCPP_EXPORT void *get_module() | ||
{ | ||
// create extension | ||
static Php::Extension extension("include_once","1.0"); | ||
|
||
// add function to extension | ||
extension.add<my_include_once>("my_include_once", { | ||
Php::ByVal("path", Php::Type::String), | ||
}); | ||
|
||
// return the extension module | ||
return extension.module(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
/** | ||
* include_once.php | ||
* | ||
* An example file to show the working of a php function call in C++. | ||
*/ | ||
|
||
/** | ||
* Include the file (should include the file only once) | ||
*/ | ||
my_include_once(__DIR__."/class.php"); | ||
my_include_once(__DIR__."/class.php"); | ||
my_include_once(__DIR__."/class.php"); | ||
|
||
/** | ||
* Construct object | ||
*/ | ||
$x = new SillyClass(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters