Skip to content

Commit 2821b33

Browse files
committed
PHP: compatibility with 8.0.0 RC1.
This closes #474 PR on GitHub.
1 parent 6ec0ff3 commit 2821b33

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

src/nxt_php_sapi.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ static void nxt_php_set_options(nxt_task_t *task, nxt_conf_value_t *options,
8888
int type);
8989
static nxt_int_t nxt_php_alter_option(nxt_str_t *name, nxt_str_t *value,
9090
int type);
91+
#ifdef NXT_PHP8
92+
static void nxt_php_disable_functions(nxt_str_t *str);
93+
#endif
9194
static void nxt_php_disable(nxt_task_t *task, const char *type,
9295
nxt_str_t *value, char **ptr, nxt_php_disable_t disable);
9396

@@ -589,9 +592,13 @@ nxt_php_set_options(nxt_task_t *task, nxt_conf_value_t *options, int type)
589592
}
590593

591594
if (nxt_str_eq(&name, "disable_functions", 17)) {
595+
#ifdef NXT_PHP8
596+
nxt_php_disable_functions(&value);
597+
#else
592598
nxt_php_disable(task, "function", &value,
593599
&PG(disable_functions),
594600
zend_disable_function);
601+
#endif
595602
continue;
596603
}
597604

@@ -680,6 +687,29 @@ nxt_php_alter_option(nxt_str_t *name, nxt_str_t *value, int type)
680687
#endif
681688

682689

690+
#ifdef NXT_PHP8
691+
692+
static void
693+
nxt_php_disable_functions(nxt_str_t *str)
694+
{
695+
char *p;
696+
697+
p = nxt_malloc(str->length + 1);
698+
if (nxt_slow_path(p == NULL)) {
699+
return;
700+
}
701+
702+
nxt_memcpy(p, str->start, str->length);
703+
p[str->length] = '\0';
704+
705+
zend_disable_functions(p);
706+
707+
nxt_free(p);
708+
}
709+
710+
#endif
711+
712+
683713
static void
684714
nxt_php_disable(nxt_task_t *task, const char *type, nxt_str_t *value,
685715
char **ptr, nxt_php_disable_t disable)

test/php/get_variables/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
header('Content-Length: 0');
33
header('X-Var-1: ' . $_GET['var1']);
4-
header('X-Var-2: ' . $_GET['var2'] . isset($_GET['var2']));
5-
header('X-Var-3: ' . $_GET['var3'] . isset($_GET['var3']));
6-
header('X-Var-4: ' . $_GET['var4'] . isset($_GET['var4']));
4+
header('X-Var-2: ' . (isset($_GET['var2']) ? $_GET['var2'] : 'not set'));
5+
header('X-Var-3: ' . (isset($_GET['var3']) ? $_GET['var3'] : 'not set'));
6+
header('X-Var-4: ' . (isset($_GET['var4']) ? $_GET['var4'] : 'not set'));
77
?>

test/php/post_variables/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
header('Content-Length: 0');
33
header('X-Var-1: ' . $_POST['var1']);
4-
header('X-Var-2: ' . $_POST['var2'] . isset($_POST['var2']));
5-
header('X-Var-3: ' . $_POST['var3'] . isset($_POST['var3']));
4+
header('X-Var-2: ' . (isset($_POST['var2']) ? $_POST['var2'] : 'not set'));
5+
header('X-Var-3: ' . (isset($_POST['var3']) ? $_POST['var3'] : 'not set'));
66
?>

test/test_php_application.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ def test_php_application_get_variables(self):
198198

199199
resp = self.get(url='/?var1=val1&var2=&var3')
200200
assert resp['headers']['X-Var-1'] == 'val1', 'GET variables'
201-
assert resp['headers']['X-Var-2'] == '1', 'GET variables 2'
202-
assert resp['headers']['X-Var-3'] == '1', 'GET variables 3'
203-
assert resp['headers']['X-Var-4'] == '', 'GET variables 4'
201+
assert resp['headers']['X-Var-2'] == '', 'GET variables 2'
202+
assert resp['headers']['X-Var-3'] == '', 'GET variables 3'
203+
assert resp['headers']['X-Var-4'] == 'not set', 'GET variables 4'
204204

205205
def test_php_application_post_variables(self):
206206
self.load('post_variables')
@@ -214,8 +214,8 @@ def test_php_application_post_variables(self):
214214
body='var1=val1&var2=',
215215
)
216216
assert resp['headers']['X-Var-1'] == 'val1', 'POST variables'
217-
assert resp['headers']['X-Var-2'] == '1', 'POST variables 2'
218-
assert resp['headers']['X-Var-3'] == '', 'POST variables 3'
217+
assert resp['headers']['X-Var-2'] == '', 'POST variables 2'
218+
assert resp['headers']['X-Var-3'] == 'not set', 'POST variables 3'
219219

220220
def test_php_application_cookies(self):
221221
self.load('cookies')

0 commit comments

Comments
 (0)