summaryrefslogtreecommitdiff
path: root/zend/global.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zend/global.cpp')
-rw-r--r--zend/global.cpp69
1 files changed, 65 insertions, 4 deletions
diff --git a/zend/global.cpp b/zend/global.cpp
index 7eea8e7..e7fef53 100644
--- a/zend/global.cpp
+++ b/zend/global.cpp
@@ -14,6 +14,67 @@
namespace Php {
/**
+ * Move constructor
+ * @param global
+ */
+Global::Global(Global &&global) _NOEXCEPT :
+ Value(std::move(global)),
+ _name(global._name),
+ _exists(global._exists)
+{
+ // remove from other global to avoid double free
+ global._name = nullptr;
+}
+
+/**
+ * Constructor for non-existing var
+ *
+ * @param name Name for the variable that does not exist
+ */
+Global::Global(const char *name) :
+ Value(),
+ _name(zend_string_init(name, ::strlen(name), 1)),
+ _exists(false) {}
+
+/**
+ * Alternative constructor for non-existing var
+ * @param name
+ */
+Global::Global(const std::string &name) :
+ Value(),
+ _name(zend_string_init(name.data(), name.size(), 1)),
+ _exists(false) {}
+
+/**
+ * Constructor to wrap zval for existing global bar
+ * @param name
+ * @param val
+ */
+Global::Global(const char *name, struct _zval_struct *val) :
+ Value(val, true),
+ _name(zend_string_init(name, ::strlen(name), 1)),
+ _exists(true) {}
+
+/**
+ * Alternative constructor to wrap zval
+ * @param name
+ * @param val
+ */
+Global::Global(const std::string &name, struct _zval_struct *val) :
+ Value(val, true),
+ _name(zend_string_init(name.data(), name.size(), 1)),
+ _exists(true) {}
+
+/**
+ * Destructor
+ */
+Global::~Global()
+{
+ // release the string
+ if (_name) zend_string_release(_name);
+}
+
+/**
* Function that is called when the value is updated
* @return Value
*/
@@ -21,19 +82,19 @@ Global &Global::update()
{
// skip if the variable already exists
if (_exists) return *this;
-
+
// we need the TSRMLS variable
TSRMLS_FETCH();
// add the variable to the globals
- zend_hash_add(EG(active_symbol_table), _name.c_str(), _name.size()+1, &_val, sizeof(zval*), NULL);
+ zend_hash_add(EG(current_execute_data)->symbol_table, _name, _val);
// add one extra reference because the variable now is a global var too
- Z_ADDREF_P(_val);
+ Z_TRY_ADDREF_P(_val);
// remember that the variable now exists
_exists = true;
-
+
// done
return *this;
}