From 0771238f6f69f3656fce7c0ec71db6746b51b464 Mon Sep 17 00:00:00 2001 From: Alexander Gabriel Date: Wed, 10 Oct 2018 23:31:38 +0200 Subject: [PATCH] Add Example for C++-Class and Tests for empty-keyword --- CMakeLists.txt | 5 +- example.c | 10 ++- example.i | 13 ++-- test_keywords.php | 179 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 199 insertions(+), 8 deletions(-) create mode 100644 test_keywords.php diff --git a/CMakeLists.txt b/CMakeLists.txt index 460a529..e0824df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,9 @@ include_directories (C:/php-sdk/phpmaster/vc${VSCMD_VER}/$ENV{VSCMD_ARG_TGT_ARCH include_directories (C:/php-sdk/phpmaster/vc${VSCMD_VER}/$ENV{VSCMD_ARG_TGT_ARCH}/php-src/TSRM) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) -add_library(example STATIC example.c) +set_property(SOURCE example.i PROPERTY CPLUSPLUS ON) +add_library(example STATIC example.cxx) swig_add_library(php_example TYPE MODULE LANGUAGE php7 SOURCES example.i) target_compile_options(php_example PRIVATE /D_WIN32 /D_WINDOWS /DWINDOWS=1 /DZEND_WIN32=1 /DPHP_WIN32=1 /DWIN32 /DNDebug /DNDEBUG /DZEND_DEBUG=0) -SWIG_LINK_LIBRARIES(php_example "C:/php-sdk/phpmaster/vc${VSCMD_VER}/$ENV{VSCMD_ARG_TGT_ARCH}/php-src/x64/Release/php7.lib") +SWIG_LINK_LIBRARIES(php_example "C:/php-sdk/phpmaster/vc${VSCMD_VER}/$ENV{VSCMD_ARG_TGT_ARCH}/php-src/$ENV{VSCMD_ARG_TGT_ARCH}/Release/php7.lib") target_link_libraries(php_example example) diff --git a/example.c b/example.c index 25044d0..163dfda 100644 --- a/example.c +++ b/example.c @@ -1,7 +1,6 @@ /* File : example.c */ double My_variable = 3.0; - /* Compute factorial of n */ int fact(int n) { if (n <= 1) return 1; @@ -11,4 +10,11 @@ int fact(int n) { /* Compute n mod m */ int my_mod(int n, int m) { return(n % m); -} \ No newline at end of file +} + +int empty = 11; + +class webObj { + public: + int empty = 5; +}; \ No newline at end of file diff --git a/example.i b/example.i index 45a6933..79be2e4 100644 --- a/example.i +++ b/example.i @@ -2,11 +2,16 @@ %module example %{ /* Put headers and other declarations here */ -extern double My_variable; -extern int fact(int); -extern int my_mod(int n, int m); +#include "example.cxx" %} extern double My_variable; extern int fact(int); -extern int my_mod(int n, int m); \ No newline at end of file +extern int my_mod(int n, int m); + +extern int empty; + +class webObj { +public: + int empty; +}; diff --git a/test_keywords.php b/test_keywords.php new file mode 100644 index 0000000..2d04f59 --- /dev/null +++ b/test_keywords.php @@ -0,0 +1,179 @@ +__halt_compiler; + +//PHPFN(array); +$array = "\n\rContent of variable array"; +echo $array; + +class test_array { + public $array = "\n\rContent of property array"; +} +$instance = new test_array; +echo $instance->array; + +//PHPFN(die); +$die = "\n\rContent of variable die"; +echo $die; + +class test_die { + public $die = "\n\rContent of property die"; +} +$instance = new test_die; +echo $instance->die; + +//PHPFN(echo); +$echo = "\n\rContent of variable echo"; +echo $echo; + +class test_echo { + public $echo = "\n\rContent of property echo"; +} +$instance = new test_echo; +echo $instance->echo; + +//PHPFN(empty); // "Language construct" +$empty = "\n\rContent of variable empty"; +echo $empty; + +class test_empty { + public $empty = "\n\rContent of property empty"; +} +$instance = new test_empty; +echo $instance->empty; + + +//PHPFN(eval); // "Language construct" +$eval = "\n\rContent of variable eval"; +echo $eval; + +class test_eval { + public $eval = "\n\rContent of property eval"; +} +$instance = new test_eval; +echo $instance->eval; + + +//PHPFN(exit); // "Language construct" +$exit = "\n\rContent of variable exit"; +echo $exit; + +class test_exit { + public $exit = "\n\rContent of property exit"; +} +$instance = new test_exit; +echo $instance->exit; + + +//PHPFN(include); // "Language construct" +$include = "\n\rContent of variable include"; +echo $include; + +class test_include { + public $include = "\n\rContent of property include"; +} +$instance = new test_include; +echo $instance->include; + + +//PHPFN(include_once); // "Language construct" +$include_once = "\n\rContent of variable include_once"; +echo $include_once; + +class test_include_once { + public $include_once = "\n\rContent of property include_once"; +} +$instance = new test_include_once; +echo $instance->include_once; + + +//PHPFN(isset); // "Language construct" +$isset = "\n\rContent of variable isset"; +echo $isset; + +class test_isset { + public $isset = "\n\rContent of property isset"; +} +$instance = new test_isset; +echo $instance->isset; + + +//PHPFN(list); // "Language construct" +$list = "\n\rContent of variable list"; +echo $list; + +class test_list { + public $list = "\n\rContent of property list"; +} +$instance = new test_list; +echo $instance->list; + + +//PHPFN(print); // "Language construct" +$print = "\n\rContent of variable print"; +echo $print; + +class test_print { + public $print = "\n\rContent of property print"; +} +$instance = new test_print; +echo $instance->print; + + +//PHPFN(require); // "Language construct" +$require = "\n\rContent of variable require"; +echo $require; + +class test_require { + public $require = "\n\rContent of property require"; +} +$instance = new test_require; +echo $instance->require; + + +//PHPFN(require_once); // "Language construct" +$require_once = "\n\rContent of variable require_once"; +echo $require_once; + +class test_require_once { + public $require_once = "\n\rContent of property require_once"; +} +$instance = new test_require_once; +echo $instance->require_once; + + +//PHPFN(return); // "Language construct" +$return = "\n\rContent of variable return"; +echo $return; + +class test_return { + public $return = "\n\rContent of property return"; +} +$instance = new test_return; +echo $instance->return; + + +//PHPFN(unset); // "Language construct" +$unset = "\n\rContent of variable unset"; +echo $unset; + +class test_unset { + public $unset = "\n\rContent of property unset"; +} +$instance = new test_unset; +echo $instance->unset; + +dl("example"); +require_once("example.php"); + +$example = new example(); + +echo $example->empty;