Re: [RFC] Deprecations for PHP 8.4

From: Date: Tue, 25 Jun 2024 16:03:02 +0000
Subject: Re: [RFC] Deprecations for PHP 8.4
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 25/06/2024 16:27, Marco Pivetta wrote:
 * uniqid(), in my case (XKCD 1172) is largely used for quickly generating a semi-random string for test purposes: a suitable replacement PRNG implementation would be welcome. Even refactoring with tools like Rector will lead to quite messy code, or added dependencies. IMO fine to get rid of **this specific implementation**, if a safe function is provided, such as random_ascii_string() or such (dunno, just a hint)
Agreed, the implementation is weird, but nothing else matches the convenience to just get "some random printable bytes". As of PHP 8.3, we finally have Random\Randomizer::getBytesFromString, but the comparison is pretty stark: $foo = uniqid(); $foo = (new \Random\Randomizer)->getBytesFromString('abcdefghijklmnopqrstuvwxyz0123456789', 13); Alternatively, you have the shorter but slightly cryptic: $foo = bin2hex(random_bytes(6)); Then again, if you _actually_ want it to be unique, rather than random, those aren't the right replacements anyway. I'd love to replace uniqid() with *something*, but I don't think we have that thing yet. -- Rowan Tommins [IMSoP]

Thread (68 messages)

« previous php.internals (#123825) next »