Skip to content

Commit 74f0570

Browse files
committed
Add tests for strlen() and in_array()
1 parent 81ac9cb commit 74f0570

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Check deprecation from bool type in weak mode for specialized strlen() opcode
3+
--FILE--
4+
<?php
5+
6+
var_dump(strlen(false));
7+
var_dump(strlen(true));
8+
9+
?>
10+
--EXPECTF--
11+
Deprecated: strlen(): Passing bool to parameter #1 ($string) of type string is deprecated in %s on line %d
12+
int(0)
13+
14+
Deprecated: strlen(): Passing bool to parameter #1 ($string) of type string is deprecated in %s on line %d
15+
int(1)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
--TEST--
2+
Check deprecation to bool type in weak mode for specialized in_array() opcode
3+
--FILE--
4+
<?php
5+
6+
$a = [
7+
5 => 5,
8+
6 => 6,
9+
'five' => '5',
10+
];
11+
12+
13+
echo "int:\n";
14+
var_dump(in_array(5, $a, 2));
15+
var_dump(in_array(5, $a, 0));
16+
var_dump(in_array('5', $a, 2));
17+
var_dump(in_array('5', $a, 0));
18+
var_dump(in_array(6, $a, 2));
19+
var_dump(in_array(6, $a, 0));
20+
21+
echo "float:\n";
22+
var_dump(in_array(5, $a, 52.45));
23+
var_dump(in_array(5, $a, -0.0));
24+
var_dump(in_array('5', $a, 52.45));
25+
var_dump(in_array('5', $a, -0.0));
26+
var_dump(in_array(6, $a, 52.45));
27+
var_dump(in_array(6, $a, -0.0));
28+
29+
echo "string:\n";
30+
var_dump(in_array(5, $a, 'hello'));
31+
var_dump(in_array(5, $a, ''));
32+
var_dump(in_array('5', $a, 'hello'));
33+
var_dump(in_array('5', $a, ''));
34+
var_dump(in_array(6, $a, 'hello'));
35+
var_dump(in_array(6, $a, ''));
36+
?>
37+
--EXPECTF--
38+
int:
39+
40+
Deprecated: in_array(): Passing int to parameter #3 ($strict) of type bool is deprecated in %s on line %d
41+
bool(true)
42+
43+
Deprecated: in_array(): Passing int to parameter #3 ($strict) of type bool is deprecated in %s on line %d
44+
bool(true)
45+
46+
Deprecated: in_array(): Passing int to parameter #3 ($strict) of type bool is deprecated in %s on line %d
47+
bool(true)
48+
49+
Deprecated: in_array(): Passing int to parameter #3 ($strict) of type bool is deprecated in %s on line %d
50+
bool(true)
51+
52+
Deprecated: in_array(): Passing int to parameter #3 ($strict) of type bool is deprecated in %s on line %d
53+
bool(true)
54+
55+
Deprecated: in_array(): Passing int to parameter #3 ($strict) of type bool is deprecated in %s on line %d
56+
bool(true)
57+
float:
58+
59+
Deprecated: in_array(): Passing float to parameter #3 ($strict) of type bool is deprecated in %s on line %d
60+
bool(true)
61+
62+
Deprecated: in_array(): Passing float to parameter #3 ($strict) of type bool is deprecated in %s on line %d
63+
bool(true)
64+
65+
Deprecated: in_array(): Passing float to parameter #3 ($strict) of type bool is deprecated in %s on line %d
66+
bool(true)
67+
68+
Deprecated: in_array(): Passing float to parameter #3 ($strict) of type bool is deprecated in %s on line %d
69+
bool(true)
70+
71+
Deprecated: in_array(): Passing float to parameter #3 ($strict) of type bool is deprecated in %s on line %d
72+
bool(true)
73+
74+
Deprecated: in_array(): Passing float to parameter #3 ($strict) of type bool is deprecated in %s on line %d
75+
bool(true)
76+
string:
77+
78+
Deprecated: in_array(): Passing string to parameter #3 ($strict) of type bool is deprecated in %s on line %d
79+
bool(true)
80+
81+
Deprecated: in_array(): Passing string to parameter #3 ($strict) of type bool is deprecated in %s on line %d
82+
bool(true)
83+
84+
Deprecated: in_array(): Passing string to parameter #3 ($strict) of type bool is deprecated in %s on line %d
85+
bool(true)
86+
87+
Deprecated: in_array(): Passing string to parameter #3 ($strict) of type bool is deprecated in %s on line %d
88+
bool(true)
89+
90+
Deprecated: in_array(): Passing string to parameter #3 ($strict) of type bool is deprecated in %s on line %d
91+
bool(true)
92+
93+
Deprecated: in_array(): Passing string to parameter #3 ($strict) of type bool is deprecated in %s on line %d
94+
bool(true)

Zend/zend_vm_def.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8766,6 +8766,15 @@ ZEND_VM_COLD_CONST_HANDLER(121, ZEND_STRLEN, CONST|TMPVAR|CV, ANY)
87668766
}
87678767
break;
87688768
}
8769+
if (UNEXPECTED(Z_TYPE_P(value) == IS_FALSE || Z_TYPE_P(value) == IS_TRUE)) {
8770+
zend_error(E_DEPRECATED,
8771+
"strlen(): Passing bool to parameter #1 ($string) of type string is deprecated");
8772+
ZVAL_LONG(EX_VAR(opline->result.var), Z_TYPE_P(value) == IS_TRUE);
8773+
if (UNEXPECTED(EG(exception))) {
8774+
HANDLE_EXCEPTION();
8775+
}
8776+
break;
8777+
}
87698778

87708779
ZVAL_COPY(&tmp, value);
87718780
if (zend_parse_arg_str_weak(&tmp, &str, 1)) {

Zend/zend_vm_execute.h

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)