summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxXx-caillou-xXx2018-08-27 17:56:03 +0200
committerjvoisin2018-08-27 15:56:03 +0000
commite43b127410ee358d01c34dd2153fa67f7cc5395b (patch)
tree661ef505fb03de25888e07489ad64305bee1eb50
parent2ad1b9ab2efefd063d9f412e56d6a642187918a1 (diff)
Enable strict mode for `in_array` with sloppy_comparison
-rw-r--r--src/sp_sloppy.c33
-rw-r--r--src/tests/sloppy_comparison_array.phpt15
2 files changed, 48 insertions, 0 deletions
diff --git a/src/sp_sloppy.c b/src/sp_sloppy.c
index 9057571..3276233 100644
--- a/src/sp_sloppy.c
+++ b/src/sp_sloppy.c
@@ -1,5 +1,8 @@
1#include "php_snuffleupagus.h"
1#include "sp_sloppy.h" 2#include "sp_sloppy.h"
2 3
4ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus)
5
3ZEND_API zend_op_array* (*orig_zend_compile_file)(zend_file_handle* file_handle, 6ZEND_API zend_op_array* (*orig_zend_compile_file)(zend_file_handle* file_handle,
4 int type) = NULL; 7 int type) = NULL;
5ZEND_API zend_op_array* (*orig_zend_compile_string)(zval* source_string, 8ZEND_API zend_op_array* (*orig_zend_compile_string)(zval* source_string,
@@ -33,7 +36,35 @@ ZEND_API zend_op_array* sp_compile_file(zend_file_handle* file_handle,
33 return opline; 36 return opline;
34} 37}
35 38
39PHP_FUNCTION(sp_in_array) {
40 void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
41 zval func_name;
42 zval params[3] = {{{0}}};
43 zval *value, *array;
44 zend_bool strict;
45
46 zend_parse_parameters(ZEND_NUM_ARGS(), "zz|b", &value, &array, &strict);
47
48 ZVAL_COPY(&params[0], value);
49 ZVAL_COPY(&params[1], array);
50 ZVAL_BOOL(&params[2], 1);
51 ZVAL_STRING(&func_name, "in_array");
52
53 handler = zend_hash_str_find_ptr(
54 SNUFFLEUPAGUS_G(sp_internal_functions_hook), "in_array", sizeof("in_array") - 1);
55 zend_internal_function *func = zend_hash_str_find_ptr(
56 CG(function_table), "in_array", sizeof("in_array") - 1);
57 func->handler = handler;
58
59 call_user_function(CG(function_table), NULL, &func_name, return_value, 3,
60 params);
61
62 func->handler = PHP_FN(sp_in_array);
63}
64
36void hook_sloppy() { 65void hook_sloppy() {
66 TSRMLS_FETCH();
67
37 if (NULL == orig_zend_compile_file) { 68 if (NULL == orig_zend_compile_file) {
38 orig_zend_compile_file = zend_compile_file; 69 orig_zend_compile_file = zend_compile_file;
39 zend_compile_file = sp_compile_file; 70 zend_compile_file = sp_compile_file;
@@ -43,4 +74,6 @@ void hook_sloppy() {
43 orig_zend_compile_string = zend_compile_string; 74 orig_zend_compile_string = zend_compile_string;
44 zend_compile_string = sp_compile_string; 75 zend_compile_string = sp_compile_string;
45 } 76 }
77
78 HOOK_FUNCTION("in_array", sp_internal_functions_hook, PHP_FN(sp_in_array));
46} 79}
diff --git a/src/tests/sloppy_comparison_array.phpt b/src/tests/sloppy_comparison_array.phpt
new file mode 100644
index 0000000..c32586d
--- /dev/null
+++ b/src/tests/sloppy_comparison_array.phpt
@@ -0,0 +1,15 @@
1--TEST--
2Sloppy comparison
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
5--INI--
6sp.configuration_file={PWD}/config/sloppy_comparison.ini
7--FILE--
8<?php
9$qwe = array(rand(1,2), "qwe");
10var_dump(in_array(0, $qwe));
11var_dump(in_array(0, $qwe, 0));
12?>
13--EXPECT--
14bool(false)
15bool(false)