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 Oct 29, 2019
1 parent cd9919e commit da21e3a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ clean:
find -name *.o | xargs ${RM}

${COMMON_SHARED_OBJECTS}:
${COMPILER} ${COMPILER_FLAGS} ${SHARED_COMPILER_FLAGS} -o $@ ${@:shared/%.o=%.cpp}
${COMPILER} ${PHP_COMPILER_FLAGS} ${SHARED_COMPILER_FLAGS} -o $@ ${@:shared/%.o=%.cpp}

${COMMON_STATIC_OBJECTS}:
${COMPILER} ${COMPILER_FLAGS} ${STATIC_COMPILER_FLAGS} -o $@ ${@:static/%.o=%.cpp}
${COMPILER} ${PHP_COMPILER_FLAGS} ${STATIC_COMPILER_FLAGS} -o $@ ${@:static/%.o=%.cpp}

${PHP_SHARED_OBJECTS}:
${COMPILER} ${PHP_COMPILER_FLAGS} ${SHARED_COMPILER_FLAGS} -o $@ ${@:shared/%.o=%.cpp}
Expand Down
11 changes: 11 additions & 0 deletions common/modifiers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @copyright 2014 Copernica BV
*/
#include "includes.h"
#include <php.h>

/**
* Set up namespace
Expand All @@ -19,13 +20,23 @@ namespace Php {
/**
* The modifiers are constants
*/
#if PHP_VERSION_ID >= 70400
const int Static = 0x10;
const int Abstract = 0x40;
const int Final = 0x20;
const int Public = 0x01;
const int Protected = 0x02;
const int Private = 0x04;
const int Const = 0;
#else
const int Static = 0x01;
const int Abstract = 0x02;
const int Final = 0x04;
const int Public = 0x100;
const int Protected = 0x200;
const int Private = 0x400;
const int Const = 0;
#endif

/**
* Modifiers that are supported for methods and properties
Expand Down
34 changes: 29 additions & 5 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,11 @@ zend_class_entry *ClassImpl::initialize(ClassBase *base, const std::string &pref
_entry->info.user.doc_comment = _self;

// set access types flags for class
#if PHP_VERSION_ID >= 70400
_entry->ce_flags |= (int)_type;
#else
_entry->ce_flags = (int)_type;
#endif

// 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 da21e3a

Please sign in to comment.