reference/hash/functions/hash-init.xml
db22a7cfcbc3af221f67e228336ac3e2d62aaf2c
...
...
@@ -11,8 +11,9 @@
11
11
<methodsynopsis>
12
12
<type>HashContext</type><methodname>hash_init</methodname>
13
13
<methodparam><type>string</type><parameter>algo</parameter></methodparam>
14
-
<methodparam choice="opt"><type>int</type><parameter>options</parameter><initializer>0</initializer></methodparam>
15
-
<methodparam choice="opt"><type>string</type><parameter>key</parameter><initializer>&null;</initializer></methodparam>
14
+
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
15
+
<methodparam choice="opt"><type>string</type><parameter>key</parameter><initializer>""</initializer></methodparam>
16
+
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>[]</initializer></methodparam>
16
17
</methodsynopsis>
17
18

18
19
</refsect1>
...
...
@@ -29,7 +30,7 @@
29
30
</listitem>
30
31
</varlistentry>
31
32
<varlistentry>
32
-
<term><parameter>options</parameter></term>
33
+
<term><parameter>flags</parameter></term>
33
34
<listitem>
34
35
<para>
35
36
Optional settings for hash generation, currently supports only one option:
...
...
@@ -42,12 +43,22 @@
42
43
<term><parameter>key</parameter></term>
43
44
<listitem>
44
45
<para>
45
-
When <constant>HASH_HMAC</constant> is specified for <parameter>options</parameter>,
46
+
When <constant>HASH_HMAC</constant> is specified for <parameter>flags</parameter>,
46
47
a shared secret key to be used with the HMAC hashing method must be supplied in this
47
48
parameter.
48
49
</para>
49
50
</listitem>
50
51
</varlistentry>
52
+
<varlistentry>
53
+
<term><parameter>options</parameter></term>
54
+
<listitem>
55
+
<para>
56
+
An array of options for the various hashing algorithms.
57
+
Currently, only the <literal>"seed"</literal> parameter is
58
+
supported by the MurmurHash variants.
59
+
</para>
60
+
</listitem>
61
+
</varlistentry>
51
62
</variablelist>
52
63
</para>
53
64
</refsect1>
...
...
@@ -61,6 +72,15 @@
61
72
</para>
62
73
</refsect1>
63
74

75
+
<refsect1 role="errors">
76
+
&reftitle.errors;
77
+
<para>
78
+
Throws a <classname>ValueError</classname> exception if
79
+
<parameter>algo</parameter> is unknown or is a non-cryptographic hash
80
+
function, or if <parameter>key</parameter> is empty.
81
+
</para>
82
+
</refsect1>
83
+

64
84
<refsect1 role="changelog">
65
85
&reftitle.changelog;
66
86
<para>
...
...
@@ -74,6 +94,20 @@
74
94
</thead>
75
95
<tbody>
76
96
<row>
97
+
<entry>8.1.0</entry>
98
+
<entry>The <parameter>options</parameter> parameter has been added.</entry>
99
+
</row>
100
+
<row>
101
+
<entry>8.0.0</entry>
102
+
<entry>
103
+
Now throws an <classname>ValueError</classname> exception if the
104
+
<parameter>algo</parameter> is unknown or is a non-cryptographic hash
105
+
function, or if <parameter>key</parameter> is empty. Previously,
106
+
&false; was returned and an <constant>E_WARNING</constant> message was
107
+
emitted.
108
+
</entry>
109
+
</row>
110
+
<row>
77
111
<entry>7.2.0</entry>
78
112
<entry>Usage of non-cryptographic hash functions (adler32, crc32, crc32b, fnv132, fnv1a32, fnv164, fnv1a64, joaat) with <constant>HASH_HMAC</constant> was disabled.</entry>
79
113
</row>
...
...
@@ -97,17 +131,23 @@
97
131
<programlisting role="php">
98
132
<![CDATA[
99
133
<?php
100
-
$ctx = hash_init('md5');
134
+
$hash = hash('sha256', 'The quick brown fox jumped over the lazy dog.');
135
+

136
+
$ctx = hash_init('sha256');
101
137
hash_update($ctx, 'The quick brown fox ');
102
138
hash_update($ctx, 'jumped over the lazy dog.');
103
-
echo hash_final($ctx);
139
+
$incremental_hash = hash_final($ctx);
140
+

141
+
echo $incremental_hash, PHP_EOL;
142
+
var_dump($hash === $incremental_hash);
104
143
?>
105
144
]]>
106
145
</programlisting>
107
146
&example.outputs;
108
147
<screen>
109
148
<![CDATA[
110
-
5c6ffbdd40d9556b73a21e63c3e0e904
149
+
68b1282b91de2c054c36629cb8dd447f12f096d3e3c587978dc2248444633483
150
+
bool(true)
111
151
]]>
112
152
</screen>
113
153
</example>
...
...
@@ -128,7 +168,6 @@ echo hash_final($ctx);
128
168
</refsect1>
129
169

130
170
</refentry>
131
-

132
171
<!-- Keep this comment at the end of the file
133
172
Local variables:
134
173
mode: sgml
135
174