summaryrefslogtreecommitdiff
path: root/src/global.cpp
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-09-12 05:46:02 -0700
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-09-12 05:46:02 -0700
commit9634a336f080bc15c1e67495eb9216d1863808f8 (patch)
tree139d3abc65f156d5e72e02364481fea370c807dc /src/global.cpp
parent68fd128d82819db1022137a45ca3224cee8ef029 (diff)
It now is possible to access global variables, using environment[varname], and to set global variable using environment[varname] = "value"
Diffstat (limited to 'src/global.cpp')
-rw-r--r--src/global.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/global.cpp b/src/global.cpp
new file mode 100644
index 0000000..af72bc0
--- /dev/null
+++ b/src/global.cpp
@@ -0,0 +1,42 @@
+/**
+ * Global.cpp
+ *
+ * Implementation for the global variable
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013 Copernica BV
+ */
+#include "includes.h"
+
+/**
+ * Namespace
+ */
+namespace Php {
+
+/**
+ * Function that is called when the value is updated
+ * @return Value
+ */
+Global &Global::update()
+{
+ // skip if the variable already exists
+ if (_exists) return *this;
+
+ // add the variable to the globals
+ zend_hash_add(EG(active_symbol_table), _name.c_str(), _name.size()+1, &_val, sizeof(zval*), NULL);
+
+ // add one extra reference because the variable now is a global var too
+ Z_ADDREF_P(_val);
+
+ // remember that the variable now exists
+ _exists = true;
+
+ // done
+ return *this;
+}
+
+/**
+ * End of namespace
+ */
+}
+