Category
stdlib (php-src-strict)
Problem
random_bytes() accepts backed enum case operands and coerces via the backing integer. Zend/php-src rejects enum cases with TypeError (ext/standard/random.c / Z_PARAM_LONG).
This is distinct from #4626 (numeric-string + LogicException vs TypeError for arrays); enum cases are a separate guard path via EnumCaseSupport / VmString::coerceStringBuiltinArg() patterns (#5780).
php-src reference
Repro (failure today)
<?php
enum E: int { case A = 1; }
try {
random_bytes(E::A);
echo "accepted\n";
} catch (TypeError $e) {
echo "TypeError\n";
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_random_bytes_enum.php
php bin/vm.php repro_random_bytes_enum.php
'
| Runtime |
Output |
| Zend PHP 8.x |
TypeError |
bin/vm.php |
accepted (silent coerce to length 1) |
Scope (this repo)
| Module |
Path |
| VM |
ext/standard/random_bytes.php — reject TYPE_ENUM_CASE before int coercion |
| Shared |
lib/VM/EnumCaseSupport.php, lib/VM/VmString.php guards |
| JIT/AOT |
ext/standard/JitRandomBytes.php — mirror VM TypeError |
| Tests |
test/compliance/cases/stdlib/random_bytes_enum_typeerror.phpt |
PHP-in-PHP: no new C in runtime/; reuse existing JitStringBuiltinArg / enum-case probes.
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter random_bytes_enum'
Related
Category
stdlib(php-src-strict)Problem
random_bytes()accepts backed enum case operands and coerces via the backing integer. Zend/php-src rejects enum cases withTypeError(ext/standard/random.c/Z_PARAM_LONG).This is distinct from #4626 (numeric-string +
LogicExceptionvsTypeErrorfor arrays); enum cases are a separate guard path viaEnumCaseSupport/VmString::coerceStringBuiltinArg()patterns (#5780).php-src reference
ext/standard/random.c—PHP_FUNCTION(random_bytes)Zend/zend_API.c—Z_PARAM_LONGrejects objects/enumsRepro (failure today)
TypeErrorbin/vm.phpaccepted(silent coerce to length1)Scope (this repo)
ext/standard/random_bytes.php— rejectTYPE_ENUM_CASEbefore int coercionlib/VM/EnumCaseSupport.php,lib/VM/VmString.phpguardsext/standard/JitRandomBytes.php— mirror VMTypeErrortest/compliance/cases/stdlib/random_bytes_enum_typeerror.phptPHP-in-PHP: no new C in
runtime/; reuse existingJitStringBuiltinArg/ enum-case probes.Done when
TypeErroron VM/JIT/AOT (notaccepted)./script/ci-fast.sh --filter random_bytes_enumgreenVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter random_bytes_enum'Related