summaryrefslogtreecommitdiffstats
path: root/115.patch
blob: e83a27fd49efa21e2dfd3c57de3f143ab5eb8dce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
From 619c2b4fb4839502c88317b3e39221647fd16d2a Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Wed, 23 Sep 2020 14:26:16 +0200
Subject: [PATCH] Fix compatibility with PHP 8

---
 tests/021.phpt |  8 ++++++--
 tests/022.phpt |  2 +-
 yac.c          | 34 +++++++++++++++++++++++++++-------
 3 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/tests/021.phpt b/tests/021.phpt
index f2f98cf..0f68258 100644
--- a/tests/021.phpt
+++ b/tests/021.phpt
@@ -13,8 +13,12 @@ $yac = new Yac("prefix");
 
 $yac->value = "value";
 
-/* can not used in writen context */
-$yac->foo->bar = "bar";
+try {
+	/* can not used in writen context */
+	$yac->foo->bar = "bar";
+} catch (Error $e) {
+	/* expected exception on PHP 8 */
+}
 
 var_dump($yac->get("value"));
 var_dump($yac->value);
diff --git a/tests/022.phpt b/tests/022.phpt
index a34a4d2..487de28 100644
--- a/tests/022.phpt
+++ b/tests/022.phpt
@@ -17,5 +17,5 @@ var_dump($yac);
 --EXPECTF--
 string(18) "Yac is not enabled"
 
-Notice: Undefined variable: yac in %s022.php on line %d
+%s: Undefined variable%syac in %s022.php on line %d
 NULL
diff --git a/yac.c b/yac.c
index 2e961f7..408e694 100644
--- a/yac.c
+++ b/yac.c
@@ -504,17 +504,27 @@ static void yac_object_free(zend_object *object) /* {{{ */ {
 }
 /* }}} */
 
-static zval* yac_read_property_ptr(zval *zobj, zval *name, int type, void **cache_slot) /* {{{ */ {
+#if PHP_VERSION_ID < 80000
+static zval* yac_read_property_ptr(zval *zobj, zval *zname, int type, void **cache_slot) /* {{{ */ {
+#else
+static zval* yac_read_property_ptr(zend_object *obj, zend_string *name, int type, void **cache_slot) /* {{{ */ {
+#endif
 	return &EG(error_zval);
 }
 /* }}} */
 
-static zval* yac_read_property(zval *zobj, zval *name, int type, void **cache_slot, zval *rv) /* {{{ */ {
+#if PHP_VERSION_ID < 80000
+static zval* yac_read_property(zval *zobj, zval *zname, int type, void **cache_slot, zval *rv) /* {{{ */ {
+	zend_object *obj = Z_OBJ_P(zobj);
+	zend_string *name = Z_STR_P(zname);
+#else
+static zval* yac_read_property(zend_object *obj, zend_string *name, int type, void **cache_slot, zval *rv) /* {{{ */ {
+#endif
 	if (UNEXPECTED(type == BP_VAR_RW||type == BP_VAR_W)) {
 		return &EG(error_zval);
 	}
 
-	if (yac_get_impl(Z_YACOBJ_P(zobj), Z_STR_P(name), NULL, rv)) {
+	if (yac_get_impl(php_yac_fetch_object(obj), name, NULL, rv)) {
 		return rv;
 	}
 
@@ -522,16 +532,26 @@ static zval* yac_read_property(zval *zobj, zval *name, int type, void **cache_sl
 }
 /* }}} */
 
-static YAC_WHANDLER yac_write_property(zval *zobj, zval *name, zval *value, void **cache_slot) /* {{{ */ {
-	yac_add_impl(Z_YACOBJ_P(zobj), Z_STR_P(name), value, 0, 0);
+#if PHP_VERSION_ID < 80000
+static YAC_WHANDLER yac_write_property(zval *zobj, zval *zname, zval *value, void **cache_slot) /* {{{ */ {
+	yac_add_impl(Z_YACOBJ_P(zobj), Z_STR_P(zname), value, 0, 0);
+#else
+static YAC_WHANDLER yac_write_property(zend_object *obj, zend_string *name, zval *value, void **cache_slot) /* {{{ */ {
+	yac_add_impl(php_yac_fetch_object(obj), name, value, 0, 0);
+#endif
     Z_TRY_ADDREF_P(value);
 
 	YAC_WHANDLER_RET(value);
 }
 /* }}} */
 
-static void yac_unset_property(zval *zobj, zval *name, void **cache_slot) /* {{{ */ {
-	yac_delete_impl(Z_YACOBJ_P(zobj), Z_STR_P(name), 0);
+#if PHP_VERSION_ID < 80000
+static void yac_unset_property(zval *zobj, zval *zname, void **cache_slot) /* {{{ */ {
+	yac_delete_impl(Z_YACOBJ_P(zobj), Z_STR_P(zname), 0);
+#else
+static void yac_unset_property(zend_object *obj, zend_string *name, void **cache_slot) /* {{{ */ {
+	yac_delete_impl(php_yac_fetch_object(obj), name, 0);
+#endif
 }
 /* }}} */