summaryrefslogtreecommitdiffstats
path: root/yaf-pr289.patch
blob: c0d8bc97fc6b4ee37e16e70427c96fb9a360bfc3 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
From bd6ffea2ca669a1614d15fdd7322994a7c50e4d0 Mon Sep 17 00:00:00 2001
From: Remi Collet <fedora@famillecollet.com>
Date: Sat, 11 Jun 2016 08:14:00 +0200
Subject: [PATCH] fix for PHP 7.1

---
 requests/yaf_request_simple.c |  2 ++
 views/yaf_view_simple.c       | 35 +++++++++++++++++++++++++++++++++--
 yaf_loader.c                  |  4 ++++
 3 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/requests/yaf_request_simple.c b/requests/yaf_request_simple.c
index 475e424..efd5934 100644
--- a/requests/yaf_request_simple.c
+++ b/requests/yaf_request_simple.c
@@ -254,8 +254,10 @@ YAF_STARTUP_FUNCTION(request_simple){
 	yaf_request_simple_ce = zend_register_internal_class_ex(&ce, yaf_request_ce);
 	yaf_request_simple_ce->ce_flags |= ZEND_ACC_FINAL;
 
+#if PHP_VERSION_ID < 70100
 	zend_declare_class_constant_string(yaf_request_simple_ce, ZEND_STRL("SCHEME_HTTP"),  "http");
 	zend_declare_class_constant_string(yaf_request_simple_ce, ZEND_STRL("SCHEME_HTTPS"), "https");
+#endif
 
 	return SUCCESS;
 }
diff --git a/views/yaf_view_simple.c b/views/yaf_view_simple.c
index 700661d..e436433 100644
--- a/views/yaf_view_simple.c
+++ b/views/yaf_view_simple.c
@@ -102,12 +102,17 @@ static int yaf_view_simple_extract(zval *tpl_vars, zval *vars) /* {{{ */ {
 
 	if (tpl_vars && Z_TYPE_P(tpl_vars) == IS_ARRAY) {
 	    ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tpl_vars), var_name, entry) {
+#if PHP_VERSION_ID < 70100
+			zend_class_entry *scope = EG(scope);
+#else
+			zend_class_entry *scope = zend_get_executed_scope();
+#endif
 			/* GLOBALS protection */
 			if (zend_string_equals_literal(var_name, "GLOBALS")) {
 				continue;
 			}
 
-			if (zend_string_equals_literal(var_name, "this") && EG(scope) && ZSTR_LEN(EG(scope)->name) != 0) {
+			if (zend_string_equals_literal(var_name, "this") && scope && ZSTR_LEN(scope->name) != 0) {
 				continue;
 			}
 
@@ -121,12 +126,17 @@ static int yaf_view_simple_extract(zval *tpl_vars, zval *vars) /* {{{ */ {
 
 	if (vars && Z_TYPE_P(vars) == IS_ARRAY) {
 	    ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(vars), var_name, entry) {
+#if PHP_VERSION_ID < 70100
+			zend_class_entry *scope = EG(scope);
+#else
+			zend_class_entry *scope = zend_get_executed_scope();
+#endif
 			/* GLOBALS protection */
 			if (zend_string_equals_literal(var_name, "GLOBALS")) {
 				continue;
 			}
 
-			if (zend_string_equals_literal(var_name, "this") && EG(scope) && ZSTR_LEN(EG(scope)->name) != 0) {
+			if (zend_string_equals_literal(var_name, "this") && scope && ZSTR_LEN(scope->name) != 0) {
 				continue;
 			}
 
@@ -257,15 +267,24 @@ int yaf_view_simple_display(yaf_view_t *view, zval *tpl, zval *vars, zval *ret)
 
 	(void)yaf_view_simple_extract(tpl_vars, vars);
 
+#if PHP_VERSION_ID < 70100
 	old_scope = EG(scope);
 	EG(scope) = yaf_view_simple_ce;
+#else
+	old_scope = EG(fake_scope);
+	EG(fake_scope) = yaf_view_simple_ce;
+#endif
 
 	if (IS_ABSOLUTE_PATH(Z_STRVAL_P(tpl), Z_STRLEN_P(tpl))) {
 		script 	= Z_STRVAL_P(tpl);
 		len 	= Z_STRLEN_P(tpl);
 		if (yaf_loader_import(script, len, 0) == 0) {
 			yaf_trigger_error(YAF_ERR_NOTFOUND_VIEW, "Failed opening template %s: %s" , script, strerror(errno));
+#if PHP_VERSION_ID < 70100
 			EG(scope) = old_scope;
+#else
+			EG(fake_scope) = old_scope;
+#endif
 			return 0;
 		}
 	} else {
@@ -278,7 +297,11 @@ int yaf_view_simple_display(yaf_view_t *view, zval *tpl, zval *vars, zval *ret)
 				yaf_trigger_error(YAF_ERR_NOTFOUND_VIEW,
 						"Could not determine the view script path, you should call %s::setScriptPath to specific it",
 						ZSTR_VAL(yaf_view_simple_ce->name));
+#if PHP_VERSION_ID < 70100
 				EG(scope) = old_scope;
+#else
+				EG(fake_scope) = old_scope;
+#endif
 				return 0;
 			}
 		} else {
@@ -288,13 +311,21 @@ int yaf_view_simple_display(yaf_view_t *view, zval *tpl, zval *vars, zval *ret)
 		if (yaf_loader_import(script, len, 0) == 0) {
 			yaf_trigger_error(YAF_ERR_NOTFOUND_VIEW, "Failed opening template %s: %s", script, strerror(errno));
 			efree(script);
+#if PHP_VERSION_ID < 70100
 			EG(scope) = old_scope;
+#else
+			EG(fake_scope) = old_scope;
+#endif
 			return 0;
 		}
 		efree(script);
 	}
 
+#if PHP_VERSION_ID < 70100
 	EG(scope) = old_scope;
+#else
+	EG(fake_scope) = old_scope;
+#endif
 
 	return 1;
 }
diff --git a/yaf_loader.c b/yaf_loader.c
index a345d58..d5cd20a 100644
--- a/yaf_loader.c
+++ b/yaf_loader.c
@@ -83,9 +83,13 @@ int yaf_loader_register(yaf_loader_t *loader) /* {{{ */ {
 	do {
 		zend_fcall_info fci = {
 			sizeof(fci),
+#if PHP_VERSION_ID < 70100
 			EG(function_table),
+#endif
 			function,
+#if PHP_VERSION_ID < 70100
 			NULL,
+#endif
 			&ret,
 			params,
 			NULL,