Skip to content

Commit a12556d

Browse files
Merge pull request #535 from aidvu/php8.4-patch
PHP-CPP: PHP 8.4 support
2 parents ad90b5a + 46d2b80 commit a12556d

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

zend/callable.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ void Callable::initialize(zend_function_entry *entry, const char *classname, int
124124
entry->arg_info = _argv.get();
125125
entry->num_args = _argc;
126126
entry->flags = flags;
127+
#if PHP_VERSION_ID >= 80400
128+
entry->frameless_function_infos = nullptr;
129+
entry->doc_comment = nullptr;
130+
#endif
127131

128132
// we should fill the first argument as well
129133
initialize((zend_internal_function_info*)_argv.get(), classname);

zend/classimpl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ ClassImpl::~ClassImpl()
2323
// destruct the entries
2424
delete[] _entries;
2525

26+
// PHP 8.4 frees doc_comment if not null, so skip.
27+
#if PHP_VERSION_ID < 80400
2628
// free the stored pointer
2729
if (_self) zend_string_release(_self);
30+
#endif
2831
}
2932

3033
/**
@@ -56,14 +59,22 @@ static ClassImpl *self(zend_class_entry *entry)
5659
* the string, in case PHP tries to read it) and after that the pointer
5760
* and we leave the doc_comment_len at 0.
5861
*/
62+
#if PHP_VERSION_ID < 80400
5963
while (entry->parent && (entry->info.user.doc_comment == nullptr || ZSTR_LEN(entry->info.user.doc_comment) > 0))
64+
#else
65+
while (entry->parent && (entry->doc_comment == nullptr || ZSTR_LEN(entry->doc_comment) > 0))
66+
#endif
6067
{
6168
// we did not create this class entry, but luckily we have a parent
6269
entry = entry->parent;
6370
}
6471

6572
// retrieve the comment (it has a pointer hidden in it to the ClassBase object)
73+
#if PHP_VERSION_ID < 80400
6674
const char *comment = ZSTR_VAL(entry->info.user.doc_comment);
75+
#else
76+
const char *comment = ZSTR_VAL(entry->doc_comment);
77+
#endif
6778

6879
// the first byte of the comment is an empty string (null character), but
6980
// the next bytes contain a pointer to the ClassBase class
@@ -1604,7 +1615,11 @@ zend_class_entry *ClassImpl::initialize(ClassBase *base, const std::string &pref
16041615
std::memcpy(ZSTR_VAL(_self) + 1, &impl, sizeof(impl));
16051616

16061617
// install the doc_comment
1618+
#if PHP_VERSION_ID < 80400
16071619
_entry->info.user.doc_comment = _self;
1620+
#else
1621+
_entry->doc_comment = _self;
1622+
#endif
16081623

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

zend/iteratorimpl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ void IteratorImpl::destructor(zend_object_iterator *iter)
6868
* @param iter
6969
* @return int
7070
*/
71+
#if PHP_VERSION_ID < 80400
7172
int IteratorImpl::valid(zend_object_iterator *iter)
73+
#else
74+
zend_result IteratorImpl::valid(zend_object_iterator *iter)
75+
#endif
7276
{
7377
// check if valid
7478
return self(iter)->valid() ? SUCCESS : FAILURE;

zend/iteratorimpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ class IteratorImpl
121121
* @param iter
122122
* @return int
123123
*/
124+
#if PHP_VERSION_ID < 80400
124125
static int valid(zend_object_iterator *iter);
126+
#else
127+
static zend_result valid(zend_object_iterator *iter);
128+
#endif
125129

126130
/**
127131
* Fetch the current item

zend/module.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,23 @@ class Module
179179
// this is not possible if the module is invalid in the first place
180180
if (!valid()) return false;
181181

182+
#if PHP_VERSION_ID < 80400
182183
// the Zend engine sets a number of properties in the entry class, we do that here too
183184
// note that it would be better to call zend_next_free_module() to find the next module
184185
// number, but some users complain that this function is not always available
185186
_entry->type = MODULE_TEMPORARY;
186187
_entry->module_number = zend_hash_num_elements(&module_registry) + 1;
188+
#endif
187189
_entry->handle = _handle;
188190

189191
// @todo does loading an extension even work in a multi-threading setup?
190192

191193
// register the module, this apparently returns a copied entry pointer
194+
#if PHP_VERSION_ID < 80400
192195
auto *entry = zend_register_module_ex(_entry);
196+
#else
197+
auto *entry = zend_register_module_ex(_entry, MODULE_TEMPORARY);
198+
#endif
193199

194200
// forget the entry, so that a new call to start() will fail too
195201
_entry = nullptr;

0 commit comments

Comments
 (0)