Skip to content

Commit 058c9c3

Browse files
Merge pull request CopernicaMarketingSoftware#522 from ebikt/php8-fix-zend-string
Php8 fix __get (by disabling void*->bool conversion)
2 parents 3cee025 + 9950a0b commit 058c9c3

File tree

7 files changed

+50
-0
lines changed

7 files changed

+50
-0
lines changed

include/class.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ class PHPCPP_EXPORT Class : private ClassBase
227227
Class<T> &property(const char *name, const char *value, int flags = Public) { ClassBase::property(name, value, flags); return *this; }
228228
Class<T> &property(const char *name, const std::string &value, int flags = Public) { ClassBase::property(name, value, flags); return *this; }
229229
Class<T> &property(const char *name, bool value, int flags = Public) { ClassBase::property(name, value, flags); return *this; }
230+
Class<T> &property(const char *name, const void *value, int flags = Public) = delete;
230231
Class<T> &property(const char *name, double value, int flags = Public) { ClassBase::property(name, value, flags); return *this; }
231232

232233
/**

include/classbase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ class PHPCPP_EXPORT ClassBase
273273
void property(const char *name, int32_t value, int flags = Php::Public);
274274
void property(const char *name, int64_t value, int flags = Php::Public);
275275
void property(const char *name, bool value, int flags = Php::Public);
276+
void property(const char *name, const void *value, int flags = Php::Public) = delete;
276277
void property(const char *name, char value, int flags = Php::Public);
277278
void property(const char *name, const std::string &value, int flags = Php::Public);
278279
void property(const char *name, const char *value, int flags = Php::Public);

include/constant.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class PHPCPP_EXPORT Constant
4444
* @param value Constant's value
4545
*/
4646
Constant(const char *name, bool value);
47+
Constant(const char *name, const void *value) = delete;
4748

4849
/**
4950
* Constructor to create a constant for a 32-bit integer

include/hashmember.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
191191
HashMember &operator+=(int32_t value) { return operator=(this->value() + value); }
192192
HashMember &operator+=(int64_t value) { return operator=(this->value() + value); }
193193
HashMember &operator+=(bool value) { return operator=(this->value() + value); }
194+
HashMember &operator+=(const void *value) = delete;
194195
HashMember &operator+=(char value) { return operator=(this->value() + value); }
195196
HashMember &operator+=(const std::string &value) { return operator=(this->value() + value); }
196197
HashMember &operator+=(const char *value) { return operator=(this->value() + value); }
@@ -206,6 +207,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
206207
HashMember &operator-=(int32_t value) { return operator=(this->value() - value); }
207208
HashMember &operator-=(int64_t value) { return operator=(this->value() - value); }
208209
HashMember &operator-=(bool value) { return operator=(this->value() - value); }
210+
HashMember &operator-=(const void *value) = delete;
209211
HashMember &operator-=(char value) { return operator=(this->value() - value); }
210212
HashMember &operator-=(const std::string &value) { return operator=(this->value() - value); }
211213
HashMember &operator-=(const char *value) { return operator=(this->value() - value); }
@@ -221,6 +223,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
221223
HashMember &operator*=(int32_t value) { return operator=(this->value() * value); }
222224
HashMember &operator*=(int64_t value) { return operator=(this->value() * value); }
223225
HashMember &operator*=(bool value) { return operator=(this->value() * value); }
226+
HashMember &operator*=(const void *value) = delete;
224227
HashMember &operator*=(char value) { return operator=(this->value() * value); }
225228
HashMember &operator*=(const std::string &value) { return operator=(this->value() * value); }
226229
HashMember &operator*=(const char *value) { return operator=(this->value() * value); }
@@ -236,6 +239,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
236239
HashMember &operator/=(int32_t value) { return operator=(this->value() / value); }
237240
HashMember &operator/=(int64_t value) { return operator=(this->value() / value); }
238241
HashMember &operator/=(bool value) { return operator=(this->value() / value); }
242+
HashMember &operator/=(const void *value) = delete;
239243
HashMember &operator/=(char value) { return operator=(this->value() / value); }
240244
HashMember &operator/=(const std::string &value) { return operator=(this->value() / value); }
241245
HashMember &operator/=(const char *value) { return operator=(this->value() / value); }
@@ -251,6 +255,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
251255
HashMember &operator%=(int32_t value) { return operator=(this->value() % value); }
252256
HashMember &operator%=(int64_t value) { return operator=(this->value() % value); }
253257
HashMember &operator%=(bool value) { return operator=(this->value() % value); }
258+
HashMember &operator%=(const void *value) = delete;
254259
HashMember &operator%=(char value) { return operator=(this->value() % value); }
255260
HashMember &operator%=(const std::string &value) { return operator=(this->value() % value); }
256261
HashMember &operator%=(const char *value) { return operator=(this->value() % value); }
@@ -266,6 +271,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
266271
Value operator+(int32_t value) { return this->value() + value; }
267272
Value operator+(int64_t value) { return this->value() + value; }
268273
Value operator+(bool value) { return this->value() + value; }
274+
Value operator+(const void *value) = delete;
269275
Value operator+(char value) { return this->value() + value; }
270276
Value operator+(const std::string &value) { return this->value() + value; }
271277
Value operator+(const char *value) { return this->value() + value; }
@@ -281,6 +287,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
281287
Value operator-(int32_t value) { return this->value() - value; }
282288
Value operator-(int64_t value) { return this->value() - value; }
283289
Value operator-(bool value) { return this->value() - value; }
290+
Value operator-(const void *value) = delete;
284291
Value operator-(char value) { return this->value() - value; }
285292
Value operator-(const std::string &value) { return this->value() - value; }
286293
Value operator-(const char *value) { return this->value() - value; }
@@ -296,6 +303,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
296303
Value operator*(int32_t value) { return this->value() * value; }
297304
Value operator*(int64_t value) { return this->value() * value; }
298305
Value operator*(bool value) { return this->value() * value; }
306+
Value operator*(const void *value) = delete;
299307
Value operator*(char value) { return this->value() * value; }
300308
Value operator*(const std::string &value) { return this->value() * value; }
301309
Value operator*(const char *value) { return this->value() * value; }
@@ -311,6 +319,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
311319
Value operator/(int32_t value) { return this->value() / value; }
312320
Value operator/(int64_t value) { return this->value() / value; }
313321
Value operator/(bool value) { return this->value() / value; }
322+
Value operator/(const void *value) = delete;
314323
Value operator/(char value) { return this->value() / value; }
315324
Value operator/(const std::string &value) { return this->value() / value; }
316325
Value operator/(const char *value) { return this->value() / value; }
@@ -326,6 +335,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
326335
Value operator%(int32_t value) { return this->value() % value; }
327336
Value operator%(int64_t value) { return this->value() % value; }
328337
Value operator%(bool value) { return this->value() % value; }
338+
Value operator%(const void *value) = delete;
329339
Value operator%(char value) { return this->value() % value; }
330340
Value operator%(const std::string &value) { return this->value() % value; }
331341
Value operator%(const char *value) { return this->value() % value; }

include/ini.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class PHPCPP_EXPORT Ini
6161
*/
6262
Ini(const char *name, bool value, const Place place = Place::All) :
6363
_name(name), _value(bool2str(value)), _place(place) {}
64+
Ini(const char *name, const void *value, const Place place = Place::All) = delete;
6465

6566
/**
6667
* Constructors for integer values

include/value.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ class PHPCPP_EXPORT Value : private HashParent
5656
Value(int32_t value);
5757
Value(int64_t value);
5858
Value(bool value);
59+
Value(const void *value) = delete;
5960
Value(char value);
6061
Value(const std::string &value);
6162
Value(const char *value, int size = -1);
63+
Value(struct _zend_string *value);
6264
Value(double value);
6365
Value(const IniValue &value);
6466

@@ -174,6 +176,7 @@ class PHPCPP_EXPORT Value : private HashParent
174176
Value &operator=(int32_t value);
175177
Value &operator=(int64_t value);
176178
Value &operator=(bool value);
179+
Value &operator=(const void *value) = delete;
177180
Value &operator=(char value);
178181
Value &operator=(const std::string &value);
179182
Value &operator=(const char *value);
@@ -191,6 +194,7 @@ class PHPCPP_EXPORT Value : private HashParent
191194
Value &operator+=(int32_t value);
192195
Value &operator+=(int64_t value);
193196
Value &operator+=(bool value);
197+
Value &operator+=(const void *value) = delete;
194198
Value &operator+=(char value);
195199
Value &operator+=(const std::string &value);
196200
Value &operator+=(const char *value);
@@ -206,6 +210,7 @@ class PHPCPP_EXPORT Value : private HashParent
206210
Value &operator-=(int32_t value);
207211
Value &operator-=(int64_t value);
208212
Value &operator-=(bool value);
213+
Value &operator-=(const void *value) = delete;
209214
Value &operator-=(char value);
210215
Value &operator-=(const std::string &value);
211216
Value &operator-=(const char *value);
@@ -221,6 +226,7 @@ class PHPCPP_EXPORT Value : private HashParent
221226
Value &operator*=(int32_t value);
222227
Value &operator*=(int64_t value);
223228
Value &operator*=(bool value);
229+
Value &operator*=(const void *value) = delete;
224230
Value &operator*=(char value);
225231
Value &operator*=(const std::string &value);
226232
Value &operator*=(const char *value);
@@ -236,6 +242,7 @@ class PHPCPP_EXPORT Value : private HashParent
236242
Value &operator/=(int32_t value);
237243
Value &operator/=(int64_t value);
238244
Value &operator/=(bool value);
245+
Value &operator/=(const void *value) = delete;
239246
Value &operator/=(char value);
240247
Value &operator/=(const std::string &value);
241248
Value &operator/=(const char *value);
@@ -251,6 +258,7 @@ class PHPCPP_EXPORT Value : private HashParent
251258
Value &operator%=(int32_t value);
252259
Value &operator%=(int64_t value);
253260
Value &operator%=(bool value);
261+
Value &operator%=(const void *value) = delete;
254262
Value &operator%=(char value);
255263
Value &operator%=(const std::string &value);
256264
Value &operator%=(const char *value);
@@ -266,6 +274,7 @@ class PHPCPP_EXPORT Value : private HashParent
266274
Value operator+(int32_t value);
267275
Value operator+(int64_t value);
268276
Value operator+(bool value);
277+
Value operator+(const void *value) = delete;
269278
Value operator+(char value);
270279
Value operator+(const std::string &value);
271280
Value operator+(const char *value);
@@ -281,6 +290,7 @@ class PHPCPP_EXPORT Value : private HashParent
281290
Value operator-(int32_t value);
282291
Value operator-(int64_t value);
283292
Value operator-(bool value);
293+
Value operator-(const void *value) = delete;
284294
Value operator-(char value);
285295
Value operator-(const std::string &value);
286296
Value operator-(const char *value);
@@ -296,6 +306,7 @@ class PHPCPP_EXPORT Value : private HashParent
296306
Value operator*(int32_t value);
297307
Value operator*(int64_t value);
298308
Value operator*(bool value);
309+
Value operator*(const void *value) = delete;
299310
Value operator*(char value);
300311
Value operator*(const std::string &value);
301312
Value operator*(const char *value);
@@ -311,6 +322,7 @@ class PHPCPP_EXPORT Value : private HashParent
311322
Value operator/(int32_t value);
312323
Value operator/(int64_t value);
313324
Value operator/(bool value);
325+
Value operator/(const void *value) = delete;
314326
Value operator/(char value);
315327
Value operator/(const std::string &value);
316328
Value operator/(const char *value);
@@ -326,13 +338,18 @@ class PHPCPP_EXPORT Value : private HashParent
326338
Value operator%(int32_t value);
327339
Value operator%(int64_t value);
328340
Value operator%(bool value);
341+
Value operator%(const void *value) = delete;
329342
Value operator%(char value);
330343
Value operator%(const std::string &value);
331344
Value operator%(const char *value);
332345
Value operator%(double value);
333346

334347
/**
335348
* Comparison operators for hardcoded strings
349+
*
350+
* Note that this works only for string values,
351+
* other values segfaults!
352+
*
336353
* @param value
337354
*/
338355
bool operator==(const char *value) const { return strcmp(value) == 0; }

zend/value.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,25 @@ Value::Value(const char *value, int size)
128128
}
129129
}
130130

131+
/**
132+
* Constructor based on zend_string
133+
* @param value
134+
*/
135+
Value::Value(struct _zend_string *value)
136+
{
137+
// is there a value?
138+
if (value)
139+
{
140+
// create a string zval
141+
ZVAL_STRINGL(_val, value->val, value->len);
142+
}
143+
else
144+
{
145+
// store null
146+
ZVAL_NULL(_val);
147+
}
148+
}
149+
131150
/**
132151
* Constructor based on decimal value
133152
* @param value

0 commit comments

Comments
 (0)