-
Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathglobalbug.cpp
52 lines (42 loc) · 1.23 KB
/
globalbug.cpp
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
/**
* globalbug.cpp
* @author Charlie Bouthoorn <[email protected]>
*
* An example file which shows a former bug in globals
*/
#define NAME "globalbug"
#define VERSION "1.0"
#include <iostream>
#include <phpcpp.h>
/**
* process_globals()
*
* This function reads and modifies global variables
*/
void process_globals()
{
// Create a global array
Php::GLOBALS["array"] = Php::Array();
// Get this global back
Php::Global array = Php::GLOBALS["array"];
// Store a value in a member field
// NOTE: This is where the bug was. Changing this value didn't
// result in the global being updated.
array["member"] = 123;
// For comparison: These two answers should be the same
std::cout << array["member"] << std::endl;
std::cout << Php::GLOBALS["array"]["member"] << std::endl;
}
// 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(NAME, VERSION);
// add function to extension
extension.add<process_globals>("process_globals");
return extension.module();
}
}