<?php
declare(strict_types=1);
// happy path (works today)
echo strlen(random_bytes(8)), "\n";
// numeric string — Zend accepts
try {
echo strlen(random_bytes('16')), "\n";
} catch (Throwable $e) {
echo 'numeric-string:', get_class($e), ':', $e->getMessage(), "\n";
}
// invalid type — Zend TypeError
try {
random_bytes([]);
} catch (Throwable $e) {
echo 'array:', get_class($e), "\n";
}
Category
stdlibProblem
random_bytes()exists on VM/JIT/AOT for integer lengths, but argument validation does not match Zend:LogicException(random_bytes() only supports integers in this compiler build) instead ofTypeError."16"are rejected; Zend coerces viazend_parse_parameterslong handling.ValueError/TypeErrorper php-src version).php-src reference
ext/standard/random.c—PHP_FUNCTION(random_bytes)ext/standard/basic_functions.stub.php— signature + errorsRepro (failure today)
random_bytes(8)8byte stringrandom_bytes('16')LogicExceptionrandom_bytes([])TypeErrorLogicExceptionScope (this repo)
ext/standard/random_bytes.php,ext/standard/VmString.phpext/standard/JitRandomBytes.php(or inline inrandom_bytes::call)test/compliance/cases/stdlib/random_bytes_type.phpt,random_bytes_jit_type.phptDone when
random_bytes('16')returns 16 bytes on VM/JIT/AOTTypeError(Zend message subset)ValueErrorlike Zendrandom_bytes*.phptstill green./script/ci-fast.sh --filter random_bytesgreenVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter random_bytes'Related