Skip to content

Commit b00f611

Browse files
committed
Fix "Use of undefined constant" error for PHP below 7.2.
1 parent 3f4c5e2 commit b00f611

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

lib/Crypto/CryptArgon2.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,22 @@ class CryptArgon2 extends AbstractAlgorithm
5454
* @param int $threads Number of threads to use for computing.
5555
*/
5656
public function __construct(
57-
IL10N $localization,
58-
$memoryCost = PASSWORD_ARGON2_DEFAULT_MEMORY_COST,
59-
$timeCost = PASSWORD_ARGON2_DEFAULT_TIME_COST,
60-
$threads = PASSWORD_ARGON2_DEFAULT_THREADS
57+
IL10N $localization, $memoryCost = -1, $timeCost = -1, $threads = -1
6158
) {
6259
if (version_compare(PHP_VERSION, "7.2.0") === -1) {
6360
throw new \RuntimeException(
6461
"PASSWORD_ARGON2I requires PHP 7.2.0 or above."
6562
);
63+
} else {
64+
if ($memoryCost === -1) {
65+
$memoryCost = PASSWORD_ARGON2_DEFAULT_MEMORY_COST;
66+
}
67+
if ($timeCost === -1) {
68+
$timeCost = PASSWORD_ARGON2_DEFAULT_TIME_COST;
69+
}
70+
if ($threads === -1) {
71+
$threads = PASSWORD_ARGON2_DEFAULT_THREADS;
72+
}
6673
}
6774

6875
parent::__construct($localization);

0 commit comments

Comments
 (0)