Skip to content

Commit 3b9b1ce

Browse files
committed
Add support for php7.4
1 parent cd9919e commit 3b9b1ce

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

zend/classimpl.cpp

+26-6
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ zend_object *ClassImpl::cloneObject(zval *val)
527527
// a copy constructor). Because this function is directly called from the
528528
// Zend engine, we can call zend_error() (which does a longjmp()) to throw
529529
// an exception back to the Zend engine)
530-
if (!cpp) zend_error(E_ERROR, "Unable to clone %s", entry->name);
530+
if (!cpp) zend_error(E_ERROR, "Unable to clone %s", entry->name->val);
531531

532532
// store the object
533533
auto *new_object = new ObjectImpl(entry, cpp, impl->objectHandlers(), 1);
@@ -915,7 +915,7 @@ zval *ClassImpl::readProperty(zval *object, zval *name, int type, void **cache_s
915915
* @param cache_slot The cache slot used
916916
* @return zval
917917
*/
918-
void ClassImpl::writeProperty(zval *object, zval *name, zval *value, void **cache_slot)
918+
PHP_WRITE_PROP_HANDLER_TYPE ClassImpl::writeProperty(zval *object, zval *name, zval *value, void **cache_slot)
919919
{
920920
// retrieve the object and class
921921
Base *base = ObjectImpl::find(object)->object();
@@ -946,7 +946,13 @@ void ClassImpl::writeProperty(zval *object, zval *name, zval *value, void **cach
946946
else
947947
{
948948
// check if it could be set
949-
if (iter->second->set(base, value)) return;
949+
if (iter->second->set(base, value)) {
950+
#if PHP_VERSION_ID >= 70400
951+
return value;
952+
#else
953+
return;
954+
#endif
955+
}
950956

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

960972
// call the default
961973
std_object_handlers.write_property(object, name, value, cache_slot);
974+
#if PHP_VERSION_ID >= 70400
975+
return value;
976+
#else
977+
return;
978+
#endif
962979
}
963980
catch (Throwable &throwable)
964981
{
965982
// object was not caught by the extension, let it end up in user space
966983
throwable.rethrow();
967984
}
985+
#if PHP_VERSION_ID >= 70400
986+
return value;
987+
#endif
968988
}
969989

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

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

14301450
// set access types flags for class
1431-
_entry->ce_flags = (int)_type;
1451+
_entry->ce_flags |= (int)_type;
14321452

14331453
// declare all member variables
14341454
for (auto &member : _members) member->initialize(_entry);

zend/classimpl.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
*/
1414
namespace Php {
1515

16+
#if PHP_VERSION_ID >= 70400
17+
# define PHP_WRITE_PROP_HANDLER_TYPE zval *
18+
#else
19+
# define PHP_WRITE_PROP_HANDLER_TYPE void
20+
#endif
21+
1622
/**
1723
* Class definition
1824
*/
@@ -257,9 +263,9 @@ class ClassImpl
257263
* @param name The name of the property
258264
* @param value The new value
259265
* @param cache_slot The cache slot used
260-
* @return zval
266+
* @return zval*
261267
*/
262-
static void writeProperty(zval *object, zval *name, zval *value, void **cache_slot);
268+
static PHP_WRITE_PROP_HANDLER_TYPE writeProperty(zval *object, zval *name, zval *value, void **cache_slot);
263269

264270
/**
265271
* Function that is called to check whether a certain property is set

zend/value.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1499,9 +1499,12 @@ bool Value::contains(const char *key, int size) const
14991499
}
15001500
else if (isObject())
15011501
{
1502+
#if PHP_VERSION_ID >= 70400
15021503
// retrieve the object pointer and check whether the property we are trying to retrieve
1504+
if (zend_check_property_access(Z_OBJ_P(_val), String(key, size), 0) == FAILURE) return false;
1505+
#else
15031506
if (zend_check_property_access(Z_OBJ_P(_val), String(key, size)) == FAILURE) return false;
1504-
1507+
#endif
15051508
// check if the 'has_property' method is available for this object
15061509
auto *has_property = Z_OBJ_HT_P(_val)->has_property;
15071510

0 commit comments

Comments
 (0)