Skip to content

Commit 7e54f15

Browse files
committed
feat(core): 添加对PHP 8.2闭包功能的支持
- 在closure.cc中添加PHP版本检查并包含zend_closures.h头文件 - 封装newClosure函数以支持PHP 8.2的闭包创建功能 - 为闭包测试添加版本兼容性编译指令 - 更新头文件中的函数声明以匹配新实现
1 parent 8714da2 commit 7e54f15

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

include/phpx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,9 @@ static inline Reference newReference() {
13101310
return Reference{};
13111311
}
13121312

1313+
#if PHP_VERSION_ID >= 80200
13131314
extern Object newClosure(const ClosureFn &fn, const ArgList &uses = {}, const Object &_this = {});
1315+
#endif
13141316

13151317
extern Object newObject(zend_class_entry *ce);
13161318
extern Object newObject(zend_class_entry *ce, const ArgList &args);

src/core/closure.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "phpx.h"
1818

19+
#if PHP_VERSION_ID >= 80200
1920
#include "zend_closures.h"
2021

2122
namespace php {
@@ -68,3 +69,4 @@ Object newClosure(const ClosureFn &fn, const ArgList &uses, const Object &_this)
6869
return {&closure, Ctor::Move};
6970
}
7071
} // namespace php
72+
#endif

tests/src/closure.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using namespace php;
66

7+
#if PHP_VERSION_ID >= 80200
78
TEST(closure, base) {
89
ClosureFn fn = [](INTERNAL_FUNCTION_PARAMETERS, Object &this_, Array &vars_) {
910
ZVAL_LONG(return_value, 1000);
@@ -19,3 +20,4 @@ TEST(closure, base) {
1920
auto rs = o("java", "php");
2021
ASSERT_EQ(rs.toInt(), 1000);
2122
}
23+
#endif

0 commit comments

Comments
 (0)