diff --git a/include/class.h b/include/class.h index e18220ad..d3f33673 100644 --- a/include/class.h +++ b/include/class.h @@ -227,6 +227,7 @@ class PHPCPP_EXPORT Class : private ClassBase Class &property(const char *name, const char *value, int flags = Public) { ClassBase::property(name, value, flags); return *this; } Class &property(const char *name, const std::string &value, int flags = Public) { ClassBase::property(name, value, flags); return *this; } Class &property(const char *name, bool value, int flags = Public) { ClassBase::property(name, value, flags); return *this; } + Class &property(const char *name, const void *value, int flags = Public) = delete; Class &property(const char *name, double value, int flags = Public) { ClassBase::property(name, value, flags); return *this; } /** diff --git a/include/classbase.h b/include/classbase.h index 3e010719..dfa2f38b 100644 --- a/include/classbase.h +++ b/include/classbase.h @@ -273,6 +273,7 @@ class PHPCPP_EXPORT ClassBase void property(const char *name, int32_t value, int flags = Php::Public); void property(const char *name, int64_t value, int flags = Php::Public); void property(const char *name, bool value, int flags = Php::Public); + void property(const char *name, const void *value, int flags = Php::Public) = delete; void property(const char *name, char value, int flags = Php::Public); void property(const char *name, const std::string &value, int flags = Php::Public); void property(const char *name, const char *value, int flags = Php::Public); diff --git a/include/constant.h b/include/constant.h index bb3a2d89..f90966a2 100644 --- a/include/constant.h +++ b/include/constant.h @@ -44,6 +44,7 @@ class PHPCPP_EXPORT Constant * @param value Constant's value */ Constant(const char *name, bool value); + Constant(const char *name, const void *value) = delete; /** * Constructor to create a constant for a 32-bit integer diff --git a/include/hashmember.h b/include/hashmember.h index 378ee905..6e8d458d 100644 --- a/include/hashmember.h +++ b/include/hashmember.h @@ -191,6 +191,7 @@ class PHPCPP_EXPORT HashMember : private HashParent HashMember &operator+=(int32_t value) { return operator=(this->value() + value); } HashMember &operator+=(int64_t value) { return operator=(this->value() + value); } HashMember &operator+=(bool value) { return operator=(this->value() + value); } + HashMember &operator+=(const void *value) = delete; HashMember &operator+=(char value) { return operator=(this->value() + value); } HashMember &operator+=(const std::string &value) { return operator=(this->value() + value); } HashMember &operator+=(const char *value) { return operator=(this->value() + value); } @@ -206,6 +207,7 @@ class PHPCPP_EXPORT HashMember : private HashParent HashMember &operator-=(int32_t value) { return operator=(this->value() - value); } HashMember &operator-=(int64_t value) { return operator=(this->value() - value); } HashMember &operator-=(bool value) { return operator=(this->value() - value); } + HashMember &operator-=(const void *value) = delete; HashMember &operator-=(char value) { return operator=(this->value() - value); } HashMember &operator-=(const std::string &value) { return operator=(this->value() - value); } HashMember &operator-=(const char *value) { return operator=(this->value() - value); } @@ -221,6 +223,7 @@ class PHPCPP_EXPORT HashMember : private HashParent HashMember &operator*=(int32_t value) { return operator=(this->value() * value); } HashMember &operator*=(int64_t value) { return operator=(this->value() * value); } HashMember &operator*=(bool value) { return operator=(this->value() * value); } + HashMember &operator*=(const void *value) = delete; HashMember &operator*=(char value) { return operator=(this->value() * value); } HashMember &operator*=(const std::string &value) { return operator=(this->value() * value); } HashMember &operator*=(const char *value) { return operator=(this->value() * value); } @@ -236,6 +239,7 @@ class PHPCPP_EXPORT HashMember : private HashParent HashMember &operator/=(int32_t value) { return operator=(this->value() / value); } HashMember &operator/=(int64_t value) { return operator=(this->value() / value); } HashMember &operator/=(bool value) { return operator=(this->value() / value); } + HashMember &operator/=(const void *value) = delete; HashMember &operator/=(char value) { return operator=(this->value() / value); } HashMember &operator/=(const std::string &value) { return operator=(this->value() / value); } HashMember &operator/=(const char *value) { return operator=(this->value() / value); } @@ -251,6 +255,7 @@ class PHPCPP_EXPORT HashMember : private HashParent HashMember &operator%=(int32_t value) { return operator=(this->value() % value); } HashMember &operator%=(int64_t value) { return operator=(this->value() % value); } HashMember &operator%=(bool value) { return operator=(this->value() % value); } + HashMember &operator%=(const void *value) = delete; HashMember &operator%=(char value) { return operator=(this->value() % value); } HashMember &operator%=(const std::string &value) { return operator=(this->value() % value); } HashMember &operator%=(const char *value) { return operator=(this->value() % value); } @@ -266,6 +271,7 @@ class PHPCPP_EXPORT HashMember : private HashParent Value operator+(int32_t value) { return this->value() + value; } Value operator+(int64_t value) { return this->value() + value; } Value operator+(bool value) { return this->value() + value; } + Value operator+(const void *value) = delete; Value operator+(char value) { return this->value() + value; } Value operator+(const std::string &value) { return this->value() + value; } Value operator+(const char *value) { return this->value() + value; } @@ -281,6 +287,7 @@ class PHPCPP_EXPORT HashMember : private HashParent Value operator-(int32_t value) { return this->value() - value; } Value operator-(int64_t value) { return this->value() - value; } Value operator-(bool value) { return this->value() - value; } + Value operator-(const void *value) = delete; Value operator-(char value) { return this->value() - value; } Value operator-(const std::string &value) { return this->value() - value; } Value operator-(const char *value) { return this->value() - value; } @@ -296,6 +303,7 @@ class PHPCPP_EXPORT HashMember : private HashParent Value operator*(int32_t value) { return this->value() * value; } Value operator*(int64_t value) { return this->value() * value; } Value operator*(bool value) { return this->value() * value; } + Value operator*(const void *value) = delete; Value operator*(char value) { return this->value() * value; } Value operator*(const std::string &value) { return this->value() * value; } Value operator*(const char *value) { return this->value() * value; } @@ -311,6 +319,7 @@ class PHPCPP_EXPORT HashMember : private HashParent Value operator/(int32_t value) { return this->value() / value; } Value operator/(int64_t value) { return this->value() / value; } Value operator/(bool value) { return this->value() / value; } + Value operator/(const void *value) = delete; Value operator/(char value) { return this->value() / value; } Value operator/(const std::string &value) { return this->value() / value; } Value operator/(const char *value) { return this->value() / value; } @@ -326,6 +335,7 @@ class PHPCPP_EXPORT HashMember : private HashParent Value operator%(int32_t value) { return this->value() % value; } Value operator%(int64_t value) { return this->value() % value; } Value operator%(bool value) { return this->value() % value; } + Value operator%(const void *value) = delete; Value operator%(char value) { return this->value() % value; } Value operator%(const std::string &value) { return this->value() % value; } Value operator%(const char *value) { return this->value() % value; } diff --git a/include/ini.h b/include/ini.h index a1899a4c..03e6d264 100644 --- a/include/ini.h +++ b/include/ini.h @@ -61,6 +61,7 @@ class PHPCPP_EXPORT Ini */ Ini(const char *name, bool value, const Place place = Place::All) : _name(name), _value(bool2str(value)), _place(place) {} + Ini(const char *name, const void *value, const Place place = Place::All) = delete; /** * Constructors for integer values diff --git a/include/value.h b/include/value.h index 64653560..8a56f87b 100644 --- a/include/value.h +++ b/include/value.h @@ -56,9 +56,11 @@ class PHPCPP_EXPORT Value : private HashParent Value(int32_t value); Value(int64_t value); Value(bool value); + Value(const void *value) = delete; Value(char value); Value(const std::string &value); Value(const char *value, int size = -1); + Value(struct _zend_string *value); Value(double value); Value(const IniValue &value); @@ -174,6 +176,7 @@ class PHPCPP_EXPORT Value : private HashParent Value &operator=(int32_t value); Value &operator=(int64_t value); Value &operator=(bool value); + Value &operator=(const void *value) = delete; Value &operator=(char value); Value &operator=(const std::string &value); Value &operator=(const char *value); @@ -191,6 +194,7 @@ class PHPCPP_EXPORT Value : private HashParent Value &operator+=(int32_t value); Value &operator+=(int64_t value); Value &operator+=(bool value); + Value &operator+=(const void *value) = delete; Value &operator+=(char value); Value &operator+=(const std::string &value); Value &operator+=(const char *value); @@ -206,6 +210,7 @@ class PHPCPP_EXPORT Value : private HashParent Value &operator-=(int32_t value); Value &operator-=(int64_t value); Value &operator-=(bool value); + Value &operator-=(const void *value) = delete; Value &operator-=(char value); Value &operator-=(const std::string &value); Value &operator-=(const char *value); @@ -221,6 +226,7 @@ class PHPCPP_EXPORT Value : private HashParent Value &operator*=(int32_t value); Value &operator*=(int64_t value); Value &operator*=(bool value); + Value &operator*=(const void *value) = delete; Value &operator*=(char value); Value &operator*=(const std::string &value); Value &operator*=(const char *value); @@ -236,6 +242,7 @@ class PHPCPP_EXPORT Value : private HashParent Value &operator/=(int32_t value); Value &operator/=(int64_t value); Value &operator/=(bool value); + Value &operator/=(const void *value) = delete; Value &operator/=(char value); Value &operator/=(const std::string &value); Value &operator/=(const char *value); @@ -251,6 +258,7 @@ class PHPCPP_EXPORT Value : private HashParent Value &operator%=(int32_t value); Value &operator%=(int64_t value); Value &operator%=(bool value); + Value &operator%=(const void *value) = delete; Value &operator%=(char value); Value &operator%=(const std::string &value); Value &operator%=(const char *value); @@ -266,6 +274,7 @@ class PHPCPP_EXPORT Value : private HashParent Value operator+(int32_t value); Value operator+(int64_t value); Value operator+(bool value); + Value operator+(const void *value) = delete; Value operator+(char value); Value operator+(const std::string &value); Value operator+(const char *value); @@ -281,6 +290,7 @@ class PHPCPP_EXPORT Value : private HashParent Value operator-(int32_t value); Value operator-(int64_t value); Value operator-(bool value); + Value operator-(const void *value) = delete; Value operator-(char value); Value operator-(const std::string &value); Value operator-(const char *value); @@ -296,6 +306,7 @@ class PHPCPP_EXPORT Value : private HashParent Value operator*(int32_t value); Value operator*(int64_t value); Value operator*(bool value); + Value operator*(const void *value) = delete; Value operator*(char value); Value operator*(const std::string &value); Value operator*(const char *value); @@ -311,6 +322,7 @@ class PHPCPP_EXPORT Value : private HashParent Value operator/(int32_t value); Value operator/(int64_t value); Value operator/(bool value); + Value operator/(const void *value) = delete; Value operator/(char value); Value operator/(const std::string &value); Value operator/(const char *value); @@ -326,6 +338,7 @@ class PHPCPP_EXPORT Value : private HashParent Value operator%(int32_t value); Value operator%(int64_t value); Value operator%(bool value); + Value operator%(const void *value) = delete; Value operator%(char value); Value operator%(const std::string &value); Value operator%(const char *value); @@ -333,6 +346,10 @@ class PHPCPP_EXPORT Value : private HashParent /** * Comparison operators for hardcoded strings + * + * Note that this works only for string values, + * other values segfaults! + * * @param value */ bool operator==(const char *value) const { return strcmp(value) == 0; } diff --git a/zend/value.cpp b/zend/value.cpp index e93826a1..45d65623 100644 --- a/zend/value.cpp +++ b/zend/value.cpp @@ -128,6 +128,25 @@ Value::Value(const char *value, int size) } } +/** + * Constructor based on zend_string + * @param value + */ +Value::Value(struct _zend_string *value) +{ + // is there a value? + if (value) + { + // create a string zval + ZVAL_STRINGL(_val, value->val, value->len); + } + else + { + // store null + ZVAL_NULL(_val); + } +} + /** * Constructor based on decimal value * @param value