47 points · by ingve · 11y ago · 48 comments
https://www.sammyk.me/security-changes-to-the-php-7-csprng-i...
You can read my arguments on the mailing list, but basically it amounted to:
$chars = 'abcdefghijklmnopqrstuvwxyz234567';
for ($i = 0; $i < 12; ++$i) {
$password .= $chars[random_int(0, 31)];
}
If random_int() returned FALSE, $password would be the string 'aaaaaaaaaaaa' (and you'd have 12 E_WARNING errors in your log).By making it an exception, random_int() will now fail closed (kill the script by default), but the developer can still handle it gracefully.
$chars = 'abcdefghijklmnopqrstuvwxyz234567';
try {
for ($i = 0; $i < 12; ++$i) {
$password .= $chars[random_int(0, 31)];
}
} catch (Throwable $e) {
$framework->template->kill('An unrecoverable fatal error occurred.');
}
Or something similar.Is it a BC break? Sure. Is it worth it? Oh yeah.
If you're going to break BC, might as well do it right.
I mean, hating PHP for copying Java OO model in 2004? Com'on... It's not like PHP ever wanted to be a fancy language.
EDIT: Apparently PHP5 was released in 2004, not 2003.
EDIT2: One thing PHP got right over Java: type-hinted parameters are not nullable by default. NullPointerException anyone?
use Psr\Log\NullLogger;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
…and then the rest of the code just uses NullLogger, LoggerInterface and LogLevel.Why NOT Java?
PHP is heavily based on C so choosing to make it's OOP features like C++ isn't a big leap.
Plus PHP is still far less enterprisey than Java so maybe the OO model isn't the real issue.
/s
Zend has made a lot of good decisions (and a few painful but livable bad ones) over the last decade.
Who knows, perhaps it's one of the biggest reasons they're so successful, however much we who know better dislike that.
But you get used to that kind of stuff writing PHP. At least Facebook is making things better.
PHP has an incredible knack for almost copying other languages' features, but making them uglier in some random way, for no particular added benefit.
(I know, I'm a hater... but seriously, why?)
You don't. This is just illustrating these classes are in the global namespace.
> PHP has an incredible knack for almost copying other languages' features, but making them uglier in some random way, for no particular added benefit.
Well you have a case for "no added benefit" typically they aren't ugly for a random reason. There's a lot of very necessary reasons for the way these things work while making a language which is still PHP. PHP isn't precompiled. PHP has autoloading of classes. PHP allows code to be imported into other code. Combining namespaces with all the other existing features isn't an easy task.
Ah, PHP.
A RuntimeException is something like "Database connection failed." A LogicException is an implementation issue (e.g. usually requires a code change to fix).