On Mon, Aug 12, 2024 at 9:58 AM John Coggeshall <[email protected]> wrote:
>
> > I’m considering adding some C++ enhancements to the Zend API.
>
>
> I would definitely like to see an RFC for this if it was to be considered..
> To me, adding a whole new way of doing things internally without completely
> removing the old way is just asking for a more brittle, potentially less
> secure, and harder to maintain codebase. The win of making it easier /
> "nicer" on a subset of developers who might prefer a C++ interface isn't
> anywhere near worth the risk IMO.
>
You aren't making any sense. Why would we remove the old way? Or why should
that be a prerequisite to improving the current API? How are functions that
simply proxy the C API inherently 'more brittle, potentially less secure,
and harder to maintain'? You haven't even seen the code in question?
```cxx
TVal(const zval *other) : TVal() { ZVAL_COPY(this, other); }
TVal(zend_long value) : TVal() { ZVAL_LONG(this, value); }
TVal(int value) : TVal() { ZVAL_LONG(this, value); }
TVal(size_t value) : TVal() { ZVAL_LONG(this, value); }
TVal(bool value) : TVal() { ZVAL_BOOL(this, value); }
TVal(std::string_view value) : TVal() { ZVAL_STRINGL(this,
value.data(), value.size()); }
TVal(double value) : TVal() { ZVAL_DOUBLE(this, value); }
TVal(const char *value) : TVal() { ZVAL_STRING(this, value); }
TVal(const std::string &value) : TVal() { ZVAL_STRINGL(this,
value.c_str(), value.size()); }
bool IsNull() const { return Z_TYPE_P(this) == IS_NULL; }
bool IsTrue() const { return Z_TYPE_P(this) == IS_TRUE; }
bool IsFalse() const { return Z_TYPE_P(this) == IS_FALSE; }
bool IsBool() const { return Z_TYPE_P(this) == IS_TRUE ||
Z_TYPE_P(this) == IS_FALSE; }
bool IsLong() const { return Z_TYPE_P(this) == IS_LONG; }
bool IsDouble() const { return Z_TYPE_P(this) == IS_DOUBLE; }
bool IsString() const { return Z_TYPE_P(this) == IS_STRING; }
bool IsArray() const { return Z_TYPE_P(this) == IS_ARRAY; }
bool IsObject() const { return Z_TYPE_P(this) == IS_OBJECT; }
bool IsInstanceOf(zend_class_entry *ce) const {
return Z_TYPE_P(this) == IS_OBJECT && (ce == Z_OBJCE_P(this) ||
instanceof_function(Z_OBJCE_P(this), ce));
}
bool IsCallable() const { return zend_is_callable((zval *) this, 0,
nullptr); }
bool IsResource() const { return Z_TYPE_P(this) == IS_RESOURCE; }
bool IsReference() const { return Z_ISREF_P(this); }
```
The above is a snippet from my current implementation, so please elaborate
on which part of that is so crazy to you.
Cheers,
Lanre.