blob: 2370a8a3b8914d061499d603b16baaf561a85172 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/**
* functionvoid.cpp
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
*
* An example file to show how global variables can be accessed
*/
/**
* Libraries used.
*/
#include <iostream>
#include <phpcpp.h>
/**
* Namespace to use
*/
using namespace std;
/**
* process_globals()
*
* This function reads and modifies global variables
*/
Php::Value process_globals()
{
// all global variables can be accessed via the Php::globals variable,
// which is more or less the same as the PHP $_GLOBALS variable
// set a global variable
Php::globals["a"] = 1;
// increment a global variable
Php::globals["b"] += 1;
// set a global variable to be an array
Php::globals["c"] = Php::Array();
// add a member to an array
Php::globals["c"]["member"] = 123;
// and increment it
Php::globals["c"]["member"] += 77;
// change value e
Php::globals["e"] = Php::globals["e"][0]("hello");
// if a global variable holds a function, we can call it
return Php::globals["d"](1,2,3);
}
// 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("globals","1.0");
// add function to extension
extension.add("process_globals", process_globals);
// return the extension module
return extension.module();
}
}
|