Issues (69)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

benchmark/compare-map-assign.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @copyright   Copyright 2016 Fwolf
4
 * @license     http://opensource.org/licenses/MIT MIT
5
 */
6
7
echo <<<TAG
8
Compare speed of array assign(initialize), used om base convert maps.
9
10
11
TAG;
12
13
14
$directAssign = function() {
15
    $map = [
16
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
17
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
18
        'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
19
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
20
        'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
21
    ];
22
23
    $reverseMap = [
24
        '0' => 0,   '1' => 1,   '2' => 2,   '3' => 3,   '4' => 4,
25
        '5' => 5,   '6' => 6,   '7' => 7,   '8' => 8,   '9' => 9,
26
        'a' => 10,  'b' => 11,  'c' => 12,  'd' => 13,  'e' => 14,
27
        'f' => 15,  'g' => 16,  'h' => 17,  'i' => 18,  'j' => 19,
28
        'k' => 20,  'l' => 21,  'm' => 22,  'n' => 23,  'o' => 24,
29
        'p' => 25,  'q' => 26,  'r' => 27,  's' => 28,  't' => 29,
30
        'u' => 30,  'v' => 31,  'w' => 32,  'x' => 33,  'y' => 34,
31
        'z' => 35,
32
        'A' => 36,  'B' => 37,  'C' => 38,  'D' => 39,  'E' => 40,
33
        'F' => 41,  'G' => 42,  'H' => 43,  'I' => 44,  'J' => 45,
34
        'K' => 46,  'L' => 47,  'M' => 48,  'N' => 49,  'O' => 50,
35
        'P' => 51,  'Q' => 52,  'R' => 53,  'S' => 54,  'T' => 55,
36
        'U' => 56,  'V' => 57,  'W' => 58,  'X' => 59,  'Y' => 60,
37
        'Z' => 61,
38
    ];
39
40
    return true || $map || $reverseMap;
0 ignored issues
show
Bug Best Practice introduced by
The expression $map of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Bug Best Practice introduced by
The expression $reverseMap of type array<string,integer> is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
41
};
42
43
44
$arrayMerge = function () {
45
    $map = array_merge(
46
        ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
47
        ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'],
48
        ['n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
49
        ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'],
50
        ['N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
51
    );
52
53
    $reverseMap = array_merge(
54
        ['0' => 0,   '1' => 1,   '2' => 2,   '3' => 3,   '4' => 4],
55
        ['5' => 5,   '6' => 6,   '7' => 7,   '8' => 8,   '9' => 9],
56
        ['a' => 10,  'b' => 11,  'c' => 12,  'd' => 13,  'e' => 14],
57
        ['f' => 15,  'g' => 16,  'h' => 17,  'i' => 18,  'j' => 19],
58
        ['k' => 20,  'l' => 21,  'm' => 22,  'n' => 23,  'o' => 24],
59
        ['p' => 25,  'q' => 26,  'r' => 27,  's' => 28,  't' => 29],
60
        ['u' => 30,  'v' => 31,  'w' => 32,  'x' => 33,  'y' => 34],
61
        ['z' => 35],
62
        ['A' => 36,  'B' => 37,  'C' => 38,  'D' => 39,  'E' => 40],
63
        ['F' => 41,  'G' => 42,  'H' => 43,  'I' => 44,  'J' => 45],
64
        ['K' => 46,  'L' => 47,  'M' => 48,  'N' => 49,  'O' => 50],
65
        ['P' => 51,  'Q' => 52,  'R' => 53,  'S' => 54,  'T' => 55],
66
        ['U' => 56,  'V' => 57,  'W' => 58,  'X' => 59,  'Y' => 60],
67
        ['Z' => 61]
68
    );
69
70
    return true || $map || $reverseMap;
0 ignored issues
show
Bug Best Practice introduced by
The expression $map of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Bug Best Practice introduced by
The expression $reverseMap of type array<string,integer> is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
71
};
72
73
74
$arrayFlip = function () {
75
    $map = array_merge(
76
        ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
77
        ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'],
78
        ['n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
79
        ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'],
80
        ['N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
81
    );
82
83
    $reverseMap = array_flip($map);
84
85
    return true || $map || $reverseMap;
0 ignored issues
show
Bug Best Practice introduced by
The expression $map of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Bug Best Practice introduced by
The expression $reverseMap of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
86
};
87
88
89
$loopAssign = function() {
90
    $dict = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
91
92
    $map = [];
93
    $reverseMap = [];
94
    for ($i = 0; $i < 62; $i++) {
95
        $char = $dict{$i};
96
        $map[] = $char;
97
        $reverseMap[$char] = $i;
98
    }
99
100
    return true || $map || $reverseMap;
0 ignored issues
show
Bug Best Practice introduced by
The expression $map of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Bug Best Practice introduced by
The expression $reverseMap of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
101
};
102
103
104
$maxLoop = 100000;
105
$time1 = $_SERVER["REQUEST_TIME_FLOAT"];
106
107
for ($i = 0; $i < $maxLoop; $i++) {
108
    $directAssign();
109
}
110
$time2 = microtime(true);
111
112
for ($i = 0; $i < $maxLoop; $i++) {
113
    $arrayMerge();
114
}
115
$time3 = microtime(true);
116
117
for ($i = 0; $i < $maxLoop; $i++) {
118
    $arrayFlip();
119
}
120
$time4 = microtime(true);
121
122
for ($i = 0; $i < $maxLoop; $i++) {
123
    $loopAssign();
124
}
125
$time5 = microtime(true);
126
127
128
echo "Direct array assign: " . ($time2 - $time1) . PHP_EOL;
129
echo "  Use array_merge(): " . ($time3 - $time2) . PHP_EOL;
130
echo "   Use array_flip(): " . ($time4 - $time3) . PHP_EOL;
131
echo "  Loop array assign: " . ($time5 - $time4) . PHP_EOL;
132
133
/**
134
 * Example result:
135
136
Direct array assign: 0.94509100914001
137
  Use array_merge(): 1.7523620128632
138
   Use array_flip(): 1.3521640300751
139
  Loop array assign: 3.1361529827118
140
141
 */
142