summaryrefslogtreecommitdiff
path: root/zend/script.cpp
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-12 18:40:12 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-12 18:40:12 +0100
commita3007b9915a0ca3eec024b714cecc609e6356e17 (patch)
treee643f7ae433dbf12e6e1828950d694b855e4ec0a /zend/script.cpp
parent74388e2735e806837cd31052c513451ec3942c0a (diff)
fixed compiling in ZTS environments (reported in issue #57)
Diffstat (limited to 'zend/script.cpp')
-rw-r--r--zend/script.cpp49
1 files changed, 44 insertions, 5 deletions
diff --git a/zend/script.cpp b/zend/script.cpp
index 58ee376..a1b5b04 100644
--- a/zend/script.cpp
+++ b/zend/script.cpp
@@ -32,13 +32,14 @@ zend_op_array *Script::compile(const char *name, const char *phpcode, size_t siz
// found there is full of zval manipulation, for which we can use the much
// simpler Php::Value object
Php::Value source(phpcode, size);
-
- // remember the old compiler options, and set new compiler options
- CompilerOptions options(ZEND_COMPILE_DEFAULT_FOR_EVAL);
-
+
// we need the tsrm_ls variable
+ // @todo it would be better if this was passed as param to the compile() method
TSRMLS_FETCH();
+ // remember the old compiler options, and set new compiler options
+ CompilerOptions options(ZEND_COMPILE_DEFAULT_FOR_EVAL TSRMLS_CC);
+
// compile the string
return zend_compile_string(source._val, (char *)name TSRMLS_CC);
}
@@ -49,10 +50,48 @@ zend_op_array *Script::compile(const char *name, const char *phpcode, size_t siz
* @param script actual PHP code
* @param size length of the string
*/
-Script::Script(const char *name, const char *phpcode, size_t size) : _opcodes(compile(name, phpcode, size))
+Script::Script(const char *name, const char *phpcode, size_t size)
{
+ // we need the tsrm_ls variable
+ TSRMLS_FETCH();
+
+ // construct opcodes
+ _opcodes = new Opcodes(compile(name, phpcode, size) TSRMLS_CC);
}
+
+/**
+ * Destructor
+ */
+Script::~Script()
+{
+ // remove opcodes
+ delete _opcodes;
+}
+
+/**
+ * Is the script a valid PHP script without syntax errors?
+ * @return bool
+ */
+bool Script::valid() const
+{
+ // check opcodes
+ return _opcodes && _opcodes->valid();
+}
+
+/**
+ * Execute the script
+ * The return value of the script is returned
+ * @return Value
+ */
+Value Script::execute() const
+{
+ // pass on to opcodes
+ if (!_opcodes) return nullptr;
+ // execute opcodes
+ return _opcodes->execute();
+}
+
/**
* End of namespace
*/