Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ PHP NEWS
collator_asort() to report UTF-8/UTF-16 conversion errors through the intl
error handler instead of emitting a warning and continuing with an empty
string. (Weilin Du)
. Fixed IntlListFormatter::__construct() leaving stale global error state
after successful calls. (Weilin Du)

- Reflection:
. Added ReflectionAttribute::inNamespace(),
Expand Down
3 changes: 3 additions & 0 deletions ext/intl/listformatter/listformatter_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ PHP_METHOD(IntlListFormatter, __construct)
zend_long type = INTL_LISTFORMATTER_FALLBACK_TYPE_AND;
zend_long width = INTL_LISTFORMATTER_FALLBACK_WIDTH_WIDE;
#endif

intl_errors_reset(LISTFORMATTER_ERROR_P(obj));

ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_STRING(locale, locale_len)
Z_PARAM_OPTIONAL
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
IntlListFormatter::__construct() resets stale errors
--EXTENSIONS--
intl
--FILE--
<?php
$formatter = new IntlListFormatter('en_US');
var_dump($formatter->format(["\x80"]));
var_dump(intl_get_error_code() === U_INVALID_CHAR_FOUND);

$formatter = new IntlListFormatter('en_US');
var_dump(intl_get_error_code());
var_dump(intl_get_error_message());
var_dump($formatter->getErrorCode());
var_dump($formatter->getErrorMessage());
?>
--EXPECT--
bool(false)
bool(true)
int(0)
string(12) "U_ZERO_ERROR"
int(0)
string(12) "U_ZERO_ERROR"
4 changes: 2 additions & 2 deletions ext/random/tests/01_functions/bug46587.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ var_dump(mt_rand(3,8));
try {
var_dump(mt_rand(8,3));
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

echo "Done.\n";
?>
--EXPECTF--
int(%d)
mt_rand(): Argument #2 ($max) must be greater than or equal to argument #1 ($min)
ValueError: mt_rand(): Argument #2 ($max) must be greater than or equal to argument #1 ($min)
Done.
1 change: 0 additions & 1 deletion ext/random/tests/01_functions/mt_rand_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ PASSED: range min = 100 max = 1000
PASSED: range min = 10500 max = 1050000
PASSED: range min = 16 max = 65536
PASSED: range min = 256 max = 448

8 changes: 4 additions & 4 deletions ext/random/tests/01_functions/random_bytes_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ Test error operation of random_bytes()
try {
$bytes = random_bytes();
} catch (TypeError $e) {
echo $e->getMessage().PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$bytes = random_bytes(0);
} catch (Error $e) {
echo $e->getMessage().PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
random_bytes() expects exactly 1 argument, 0 given
random_bytes(): Argument #1 ($length) must be greater than 0
ArgumentCountError: random_bytes() expects exactly 1 argument, 0 given
ValueError: random_bytes(): Argument #1 ($length) must be greater than 0
12 changes: 6 additions & 6 deletions ext/random/tests/01_functions/random_int_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ Test error operation of random_int()
try {
$randomInt = random_int();
} catch (TypeError $e) {
echo $e->getMessage().PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$randomInt = random_int(42);
} catch (TypeError $e) {
echo $e->getMessage().PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$randomInt = random_int(42,0);
} catch (Error $e) {
echo $e->getMessage().PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
random_int() expects exactly 2 arguments, 0 given
random_int() expects exactly 2 arguments, 1 given
random_int(): Argument #1 ($min) must be less than or equal to argument #2 ($max)
ArgumentCountError: random_int() expects exactly 2 arguments, 0 given
ArgumentCountError: random_int() expects exactly 2 arguments, 1 given
ValueError: random_int(): Argument #1 ($min) must be less than or equal to argument #2 ($max)
40 changes: 20 additions & 20 deletions ext/random/tests/02_engine/all_serialize_error.phpt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ext/random/tests/02_engine/mt19937_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use Random\Engine\Mt19937;
try {
new Mt19937(1234, 2);
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
Random\Engine\Mt19937::__construct(): Argument #2 ($mode) must be either MT_RAND_MT19937 or MT_RAND_PHP
ValueError: Random\Engine\Mt19937::__construct(): Argument #2 ($mode) must be either MT_RAND_MT19937 or MT_RAND_PHP
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $referenceEngine = new PcgOneseq128XslRr64(1234);
try {
$engine->jump(-1);
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

for ($i = 0; $i < 10_000; $i++) {
Expand All @@ -24,5 +24,5 @@ die('success');

?>
--EXPECT--
Random\Engine\PcgOneseq128XslRr64::jump(): Argument #1 ($advance) must be greater than or equal to 0
ValueError: Random\Engine\PcgOneseq128XslRr64::jump(): Argument #1 ($advance) must be greater than or equal to 0
success
8 changes: 4 additions & 4 deletions ext/random/tests/02_engine/pcgoneseq128xslrr64_seed.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ echo "Invalid data type", PHP_EOL;
try {
$engine = new PcgOneseq128XslRr64(1.0);
} catch (TypeError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
echo PHP_EOL, PHP_EOL;

echo "Invalid string seed length", PHP_EOL;
try {
$engine = new PcgOneseq128XslRr64('foobar');
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
echo PHP_EOL, PHP_EOL;

Expand All @@ -49,11 +49,11 @@ Random string seed


Invalid data type
Random\Engine\PcgOneseq128XslRr64::__construct(): Argument #1 ($seed) must be of type string|int|null, float given
TypeError: Random\Engine\PcgOneseq128XslRr64::__construct(): Argument #1 ($seed) must be of type string|int|null, float given


Invalid string seed length
Random\Engine\PcgOneseq128XslRr64::__construct(): Argument #1 ($seed) must be a 16 byte (128 bit) string
ValueError: Random\Engine\PcgOneseq128XslRr64::__construct(): Argument #1 ($seed) must be a 16 byte (128 bit) string


Valid string seed
Expand Down
12 changes: 6 additions & 6 deletions ext/random/tests/02_engine/xoshiro256starstar_seed.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ echo "Invalid data type", PHP_EOL;
try {
$engine = new Xoshiro256StarStar(1.0);
} catch (Throwable $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
echo PHP_EOL, PHP_EOL;

echo "Invalid string seed length", PHP_EOL;
try {
$engine = new Xoshiro256StarStar('foobar');
} catch (Throwable $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
echo PHP_EOL, PHP_EOL;

echo "Null seed", PHP_EOL;
try {
$engine = new Xoshiro256StarStar(str_repeat("\x00", 32));
} catch (Throwable $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
echo PHP_EOL, PHP_EOL;

Expand All @@ -57,15 +57,15 @@ Random string seed


Invalid data type
Random\Engine\Xoshiro256StarStar::__construct(): Argument #1 ($seed) must be of type string|int|null, float given
TypeError: Random\Engine\Xoshiro256StarStar::__construct(): Argument #1 ($seed) must be of type string|int|null, float given


Invalid string seed length
Random\Engine\Xoshiro256StarStar::__construct(): Argument #1 ($seed) must be a 32 byte (256 bit) string
ValueError: Random\Engine\Xoshiro256StarStar::__construct(): Argument #1 ($seed) must be a 32 byte (256 bit) string


Null seed
Random\Engine\Xoshiro256StarStar::__construct(): Argument #1 ($seed) must not consist entirely of NUL bytes
ValueError: Random\Engine\Xoshiro256StarStar::__construct(): Argument #1 ($seed) must not consist entirely of NUL bytes


Valid string seed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ GH-21731: Xoshiro256StarStar::__unserialize() must reject the all-zero state
try {
var_dump(unserialize('O:32:"Random\Engine\Xoshiro256StarStar":2:{i:0;a:0:{}i:1;a:4:{i:0;s:16:"0000000000000000";i:1;s:16:"0000000000000000";i:2;s:16:"0000000000000000";i:3;s:16:"0000000000000000";}}'));
} catch (\Exception $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
Invalid serialization data for Random\Engine\Xoshiro256StarStar object
Exception: Invalid serialization data for Random\Engine\Xoshiro256StarStar object
16 changes: 8 additions & 8 deletions ext/random/tests/03_randomizer/construct_twice.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ require __DIR__ . "/../engines.inc";
try {
(new Randomizer())->__construct();
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$randomizer = new Randomizer(new Xoshiro256StarStar());
$randomizer->__construct(new PcgOneseq128XslRr64());
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$randomizer = new Randomizer(new TestShaEngine("1234"));
$randomizer->__construct(new TestShaEngine("1234"));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$randomizer = new Randomizer(new Xoshiro256StarStar());
$randomizer->__construct(new TestShaEngine("1234"));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

var_dump($randomizer->engine::class);
Expand All @@ -44,9 +44,9 @@ die('success');

?>
--EXPECT--
Cannot modify readonly property Random\Randomizer::$engine
Cannot modify readonly property Random\Randomizer::$engine
Cannot modify readonly property Random\Randomizer::$engine
Cannot modify readonly property Random\Randomizer::$engine
Error: Cannot modify readonly property Random\Randomizer::$engine
Error: Cannot modify readonly property Random\Randomizer::$engine
Error: Cannot modify readonly property Random\Randomizer::$engine
Error: Cannot modify readonly property Random\Randomizer::$engine
string(32) "Random\Engine\Xoshiro256StarStar"
success
32 changes: 16 additions & 16 deletions ext/random/tests/03_randomizer/engine_unsafe_biased.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,65 @@ function randomizer(): Randomizer
try {
var_dump(randomizer()->getInt(0, 1234));
} catch (Random\BrokenRandomEngineError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
var_dump(randomizer()->nextInt());
} catch (Random\BrokenRandomEngineError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
var_dump(bin2hex(randomizer()->getBytes(1)));
} catch (Random\BrokenRandomEngineError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
var_dump(randomizer()->shuffleArray(range(1, 1234)));
} catch (Random\BrokenRandomEngineError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
var_dump(randomizer()->pickArrayKeys(range(1, 1234), 1));
} catch (Random\BrokenRandomEngineError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
var_dump(randomizer()->pickArrayKeys(range(1, 1234), 10));
} catch (Random\BrokenRandomEngineError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
var_dump(randomizer()->shuffleBytes('foobar'));
} catch (Random\BrokenRandomEngineError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
var_dump(randomizer()->getBytesFromString('123', 10));
} catch (Random\BrokenRandomEngineError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
var_dump(randomizer()->getBytesFromString(str_repeat('a', 500), 10));
} catch (Random\BrokenRandomEngineError $e) {
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECTF--
Failed to generate an acceptable random number in 50 attempts
Random\BrokenRandomEngineError: Failed to generate an acceptable random number in 50 attempts
int(%d)
string(2) "ff"
Failed to generate an acceptable random number in 50 attempts
Failed to generate an acceptable random number in 50 attempts
Failed to generate an acceptable random number in 50 attempts
Failed to generate an acceptable random number in 50 attempts
Failed to generate an acceptable random number in 50 attempts
Failed to generate an acceptable random number in 50 attempts
Random\BrokenRandomEngineError: Failed to generate an acceptable random number in 50 attempts
Random\BrokenRandomEngineError: Failed to generate an acceptable random number in 50 attempts
Random\BrokenRandomEngineError: Failed to generate an acceptable random number in 50 attempts
Random\BrokenRandomEngineError: Failed to generate an acceptable random number in 50 attempts
Random\BrokenRandomEngineError: Failed to generate an acceptable random number in 50 attempts
Random\BrokenRandomEngineError: Failed to generate an acceptable random number in 50 attempts
Loading