Skip to content

Commit

Permalink
Add support for php7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
gnat42 committed Sep 18, 2019
1 parent cd9919e commit 3b9b1ce
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
32 changes: 26 additions & 6 deletions zend/classimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ zend_object *ClassImpl::cloneObject(zval *val)
// a copy constructor). Because this function is directly called from the
// Zend engine, we can call zend_error() (which does a longjmp()) to throw
// an exception back to the Zend engine)
if (!cpp) zend_error(E_ERROR, "Unable to clone %s", entry->name);
if (!cpp) zend_error(E_ERROR, "Unable to clone %s", entry->name->val);

// store the object
auto *new_object = new ObjectImpl(entry, cpp, impl->objectHandlers(), 1);
Expand Down Expand Up @@ -915,7 +915,7 @@ zval *ClassImpl::readProperty(zval *object, zval *name, int type, void **cache_s
* @param cache_slot The cache slot used
* @return zval
*/
void ClassImpl::writeProperty(zval *object, zval *name, zval *value, void **cache_slot)
PHP_WRITE_PROP_HANDLER_TYPE ClassImpl::writeProperty(zval *object, zval *name, zval *value, void **cache_slot)
{
// retrieve the object and class
Base *base = ObjectImpl::find(object)->object();
Expand Down Expand Up @@ -946,7 +946,13 @@ void ClassImpl::writeProperty(zval *object, zval *name, zval *value, void **cach
else
{
// check if it could be set
if (iter->second->set(base, value)) return;
if (iter->second->set(base, value)) {
#if PHP_VERSION_ID >= 70400
return value;
#else
return;
#endif
}

// read-only property
zend_error(E_ERROR, "Unable to write to read-only property %s", (const char *)key);
Expand All @@ -955,16 +961,30 @@ void ClassImpl::writeProperty(zval *object, zval *name, zval *value, void **cach
catch (const NotImplemented &exception)
{
// __set() function was not overridden by user, check if there is a default
if (!std_object_handlers.write_property) return;
if (!std_object_handlers.write_property) {
#if PHP_VERSION_ID >= 70400
return value;
#else
return;
#endif
}

// call the default
std_object_handlers.write_property(object, name, value, cache_slot);
#if PHP_VERSION_ID >= 70400
return value;
#else
return;
#endif
}
catch (Throwable &throwable)
{
// object was not caught by the extension, let it end up in user space
throwable.rethrow();
}
#if PHP_VERSION_ID >= 70400
return value;
#endif
}

/**
Expand Down Expand Up @@ -1150,7 +1170,7 @@ zend_object *ClassImpl::createObject(zend_class_entry *entry)
// report error on failure, because this function is called directly from the
// Zend engine, we can call zend_error() here (which does a longjmp() back to
// the Zend engine)
if (!cpp) zend_error(E_ERROR, "Unable to instantiate %s", entry->name);
if (!cpp) zend_error(E_ERROR, "Unable to instantiate %s", entry->name->val);

// create the object in the zend engine
auto *object = new ObjectImpl(entry, cpp, impl->objectHandlers(), 1);
Expand Down Expand Up @@ -1428,7 +1448,7 @@ zend_class_entry *ClassImpl::initialize(ClassBase *base, const std::string &pref
_entry->info.user.doc_comment = _self;

// set access types flags for class
_entry->ce_flags = (int)_type;
_entry->ce_flags |= (int)_type;

// declare all member variables
for (auto &member : _members) member->initialize(_entry);
Expand Down
10 changes: 8 additions & 2 deletions zend/classimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
*/
namespace Php {

#if PHP_VERSION_ID >= 70400
# define PHP_WRITE_PROP_HANDLER_TYPE zval *
#else
# define PHP_WRITE_PROP_HANDLER_TYPE void
#endif

/**
* Class definition
*/
Expand Down Expand Up @@ -257,9 +263,9 @@ class ClassImpl
* @param name The name of the property
* @param value The new value
* @param cache_slot The cache slot used
* @return zval
* @return zval*
*/
static void writeProperty(zval *object, zval *name, zval *value, void **cache_slot);
static PHP_WRITE_PROP_HANDLER_TYPE writeProperty(zval *object, zval *name, zval *value, void **cache_slot);

/**
* Function that is called to check whether a certain property is set
Expand Down
5 changes: 4 additions & 1 deletion zend/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1499,9 +1499,12 @@ bool Value::contains(const char *key, int size) const
}
else if (isObject())
{
#if PHP_VERSION_ID >= 70400
// retrieve the object pointer and check whether the property we are trying to retrieve
if (zend_check_property_access(Z_OBJ_P(_val), String(key, size), 0) == FAILURE) return false;
#else
if (zend_check_property_access(Z_OBJ_P(_val), String(key, size)) == FAILURE) return false;

#endif
// check if the 'has_property' method is available for this object
auto *has_property = Z_OBJ_HT_P(_val)->has_property;

Expand Down

0 comments on commit 3b9b1ce

Please sign in to comment.