Skip to content

Commit

Permalink
Merge pull request #522 from ebikt/php8-fix-zend-string
Browse files Browse the repository at this point in the history
Php8 fix __get (by disabling void*->bool conversion)
  • Loading branch information
EmielBruijntjes committed Apr 20, 2024
2 parents 3cee025 + 9950a0b commit 058c9c3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class PHPCPP_EXPORT Class : private ClassBase
Class<T> &property(const char *name, const char *value, int flags = Public) { ClassBase::property(name, value, flags); return *this; }
Class<T> &property(const char *name, const std::string &value, int flags = Public) { ClassBase::property(name, value, flags); return *this; }
Class<T> &property(const char *name, bool value, int flags = Public) { ClassBase::property(name, value, flags); return *this; }
Class<T> &property(const char *name, const void *value, int flags = Public) = delete;
Class<T> &property(const char *name, double value, int flags = Public) { ClassBase::property(name, value, flags); return *this; }

/**
Expand Down
1 change: 1 addition & 0 deletions include/classbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions include/constant.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions include/hashmember.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand All @@ -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); }
Expand All @@ -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); }
Expand All @@ -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); }
Expand All @@ -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); }
Expand All @@ -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; }
Expand All @@ -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; }
Expand All @@ -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; }
Expand All @@ -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; }
Expand All @@ -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; }
Expand Down
1 change: 1 addition & 0 deletions include/ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions include/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -326,13 +338,18 @@ 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);
Value operator%(double value);

/**
* 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; }
Expand Down
19 changes: 19 additions & 0 deletions zend/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 058c9c3

Please sign in to comment.