magento2: TypeError when using PHP 7.2 [Magento 2.3 beta]
Preconditions (*)
- Magento 2.3 beta (any edition)
- PHP 7.2.10
Steps to reproduce (*)
- Create admin user
- Attempt login with credentials
Expected result (*)
- Admin user is logged in
Actual result (*)
- Error is thrown:
TypeError: explode() expects parameter 2 to be string, integer given
#13 <magento_path>/vendor/magento/framework/Encryption/Encryptor.php(266): explode
#12 <magento_path>/vendor/magento/framework/Encryption/Encryptor.php(266): getPasswordVersion
Why this happens
More recent versions of Magento sets the declare(strict_types=1); flag in most (all?) classes.
The hash version passed to the explode function is an integer
const HASH_VERSION_SHA256 = 1;
const HASH_VERSION_LATEST = 1;
const PASSWORD_VERSION = 2;
const DELIMITER = ':';
private $passwordHashMap = [
self::PASSWORD_VERSION => self::HASH_VERSION_LATEST
];
private function getPasswordVersion()
{
return array_map('intval', explode(self::DELIMITER, $this->passwordHashMap[self::PASSWORD_VERSION]));
}
Method definition of explode
array explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] )
Notice how the $string parameter requires a string type, but the given value resolves to an integer (1).
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (4 by maintainers)
I lot of people can login indeed, and a lot of people cannot. In our case the problem was probably that the user password hash was made with an older version of magento. After upgrade some users couldn’t log in. Eventually we made a query to update password hashes and it seemed to work. The users with problems had this kind of hash: 123123123abcd We made an update to appen ::0 at the end. So it became 123123123abcd::0 And that error with explode disappeared. The default integer 1 was not used any more. However I don’t know if it is the ‘best practice’.
is this solved finally? I get the same error in 2.3., with php 7.2