diff --git a/.phan/config.php b/.phan/config.php index a1e36bb8eda..13f913885e3 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -26,6 +26,7 @@ $cfg['file_list'] = array_merge( class_exists( PEAR::class ) ? [] : [ '.phan/stubs/mail.php' ], defined( 'PASSWORD_ARGON2ID' ) ? [] : [ '.phan/stubs/password.php' ], class_exists( ExcimerProfiler::class ) ? [] : [ '.phan/stubs/excimer.php' ], + class_exists( ValueError::class ) ? [] : [ '.phan/stubs/ValueError.php' ], [ // This makes constants and globals known to Phan before processing all other files. // You can check the parser order with --dump-parsed-file-list diff --git a/.phan/stubs/ValueError.php b/.phan/stubs/ValueError.php new file mode 100644 index 00000000000..64a9450dbbc --- /dev/null +++ b/.phan/stubs/ValueError.php @@ -0,0 +1,6 @@ +args[] = base64_encode( random_bytes( 16 ) ); } - $hash = hash_pbkdf2( - $this->params['algo'], - $password, - base64_decode( $this->args[0] ), - (int)$this->params['rounds'], - (int)$this->params['length'], - true - ); - if ( !is_string( $hash ) ) { - throw new PasswordError( 'Error when hashing password.' ); + try { + $hash = hash_pbkdf2( + $this->params['algo'], + $password, + base64_decode( $this->args[0] ), + (int)$this->params['rounds'], + (int)$this->params['length'], + true + ); + + // PHP < 8 raises a warning in case of an error, such as unknown algorithm... + if ( !is_string( $hash ) ) { + throw new PasswordError( 'Error when hashing password.' ); + } + } catch ( ValueError $e ) { + // ...while PHP 8 throws ValueError + throw new PasswordError( 'Error when hashing password.', 0, $e ); } $this->hash = base64_encode( $hash );