-
-
Notifications
You must be signed in to change notification settings - Fork 205
Open
Description
Related to #1589
Analysis
This analysis covers two related changes.
PHP 8.3 adds new methods to the existing \Random\Randomizer class:
final class Random\Randomizer {
// ...
public getBytesFromString(string $string, int $length): string
public nextFloat(): float
public nextInt(): int
}PHP 8.3 adds a new enum \Random\IntervalBoundary:
enum IntervalBoundary {
case ClosedOpen;
case ClosedClosed;
case OpenClosed;
case OpenOpen;
}- The
\Random\IntervalBoundaryclass name becomes reserved - The RFC also mentions that the random extension reserves the \Random namespace. This is not new and doesn't emit warnings, but perhaps still worth flagging any classes defined in that namespace.
Top 2000 Packages
The only backward-incompatible change is the reserved name, so I looked for all declarations of the \Random namespace, and the only hits I got were stubs in static analysis tools, which is expected and not an issue. Example occurrence locations:
- /phpstan/php-8-stubs/stubs/ext/random/Random/IntervalBoundary.php
- /jetbrains/phpstorm-stubs/random/random.php
- /symfony/polyfill-php82/Resources/stubs/Random/Engine.php
Detection in PHP 8.1
\Random: ✅ Not yet introduced in that version
Detection in PHP 8.2
- Any existing class declarations in
\Randomnamespace: ❌ Existing class - Any other class declarations in
\Randomnamespace:⚠️ Reserved namespace (perhaps no need to check forIntervalBoundaryspecifically) - Usage of the
\Random\IntervalBoundaryenum: ❌ Doesn't exist yet Randomizer::getBytesFromString: ❌ Doesn't exist yetRandomizer::nextFloat: ❌ Doesn't exist yetRandomizer::nextInt: ❌ Doesn't exist yet
Detection in PHP 8.3
- Declaration of a
\Random\IntervalBoundaryclass: ❌ Existing class - Any other class declarations in
\Randomnamespace:⚠️ Reserved namespace - Usage of the
\Random\IntervalBoundaryenum: ✅ Valid - Usage of
\Random\IntervalBoundarycases : ✅ Valid Randomizer::getBytesFromString: ✅ ValidRandomizer::nextFloat: ✅ ValidRandomizer::nextInt: ✅ Valid
Syntax Variations
- Reserved classname 1
- Reserved classname 2
- Ways to interact with Randomizer methods
- Ways to interact with IntervalBoundary enum
Detectability
- Class declarations inside a specific namespace: ✅ Detectable with PHPCompatibility
- Usage of the
IntervalBoundaryenum: ✅ Mostly feasible, except when the classname becomes dynamic. - Usage of the
IntervalBoundaryenum cases:⚠️ Since we can assign an enum to a variable, we can lose track, so not all scenarios can be detected. - Usage of new
Randomizermethods:⚠️ Since we can assign the instance to a variable, we can lose track, so not all scenarios can be detected.
Examples in "Syntax Variations" above.
References
Metadata
Metadata
Assignees
Labels
No labels