Rust

PHP functions

Every PHP function, method and engine behaviour php_std reimplements, where it lives in Rust, and how it is proven against the real PHP.
146PHP functions and behaviours106 functions, 28 methods, 12 behaviours
16Groups
1,621Compat casesover 143 operations
692,570Fuzz inputs per run226 profiles
37,994Lines of Rust33,127 code, 1,696 in tests

Why php-std exists#

A Utopia crate has to behave exactly like its PHP library, and much of that behaviour comes from the PHP engine, not the library: how "10" == "1e1" compares, how a float prints as a string, which bytes strtolower touches, how mb_strtolower handles a final sigma, what json_encode escapes. Rust's own functions differ in these details, and every difference is a response that changes byte for byte.

So each engine function is reimplemented once, here, and checked against the real one by bin/compat: recorded cases, then fuzzing with generated inputs on every run. Crates call these functions instead of approximations of their own. Quirks PHP has are kept on purpose and pinned by a case; inputs a Rust type cannot represent are recorded as deviations.

Size

PartCodeCommentsBlankTotalFiles
Rust source33,1273,2821,58537,99448
Rust tests1,549291181,69632

Inventory#

Cases and fuzz inputs are those of the compat operations exercising each entry; an operation exercising several entries counts for each.

146 of 146

Strings

Byte-string functions of ext/standard/string.c and ext/ctype, plus crypt(), password_hash() / password_verify() and hash().

PHPRustCasesFuzzQuirksUsed by
addcslashes()
12,000
crypt()
24,000
ctype_alnum()
245,000
ctype_digit()
175,000
ctype_xdigit()
165,000
escapeshellarg()
43,000
explode()
63,000
hash()
28,000
lcfirst()
12,000
ltrim()
13,000
password_hash()
2—
password_verify()
23,000
rtrim()
13,000
str_contains()
12,000
str_replace()
58,000
str_starts_with()
62,000
strcasecmp()
12,000
strcmp()
22,000
strip_tags()
410,000
stripcslashes()
13,000
stripos()
13,000
strtolower()
13,000
strtoupper()
13,000
strtr()
46,000
strval()
44,000
—
substr()
53,000
trim()
63,000
ucfirst()
12,000
ucwords()
33,000

Multibyte strings

Multibyte (mbstring) functions on UTF-8.

PHPRustCasesFuzzQuirksUsed by
mb_check_encoding()
23,000
mb_convert_encoding()
12,000
mb_scrub()
13,000
mb_strimwidth()
53,000
mb_strlen()
35,000
mb_strpos()
34,000
mb_strtolower()
59,000
mb_substr()
34,000

Encoding

Encodings: URL encoding, http_build_query, base64, hex, HTML entities and quoted-printable.

PHPRustCasesFuzzQuirksUsed by
base64_decode()
85,000
base64_encode()
13,000
bin2hex()
12,000
hex2bin()
33,000
htmlentities()
48,000
htmlspecialchars()
88,000
http_build_query()
84,000
parse_str()
195,000
quoted_printable_encode()
13,000
rawurldecode()
13,000
rawurlencode()
13,000
urldecode()
23,000
urlencode()
13,000

Numbers and formatting

Number formatting and casts: sprintf, number_format, round/ceil, intval/floatval and the (int) / (float) casts, fmod, max/min of numbers.

PHPRustCasesFuzzQuirksUsed by
** exponentiationbehaviour
128,000
+ - * / arithmeticbehaviour
84,000
array_sum()
22,000
ceil()
12,000
floatval()
56,000
fmod()
22,000
intval()
1512,000
appwrite-coremongo
max()
1110,000
min()
810,000
number_format()
126,000
round()
138,000
sprintf()
2819,000

Types, juggling and comparison

PHP value semantics (type juggling) on top of serde_json::Value.

PHPRustCasesFuzzQuirksUsed by
(bool) castbehaviour
255,000
(float) castbehaviour
3611,000
(string) castbehaviour
276,000
< <= > >= orderingbehaviour
6415,000
<=> comparisonbehaviour
6110,000
== loose comparisonbehaviour
7023,000
=== strict comparisonbehaviour
6110,000
Array keys and writesbehaviour
164,000
The value model holds every PHP value of the wirebehaviour
—
43,000
—
Utopia\Http\Request decoding behaviour
32,000
empty()
12,000
appwrite-coredomainshttp
gettype()
243,000
is_numeric()
36,000
unset()
164,000

Arrays and sorting

PHP's array sorting and set functions: sort, ksort, array_unique, array_diff, array_intersect, in_array and array_search, with the SORT_* flags.

PHPRustCasesFuzzQuirksUsed by
array_diff()
43,000
array_intersect()
45,000
array_search()
23,000
array_unique()
63,000
in_array()
43,000
ksort()
53,020
sort()
178,020

Dates and times

Date and time: date()/DateTime::format, DateTime parsing and timezones, strtotime, microtime.

PHPRustCasesFuzzQuirksUsed by
DateInterval::createFromDateStringmethod
114,000
DateTime::__constructmethod
117,000
DateTime::createFromFormatmethod
164,000
DateTime::formatmethod
2711,000
DateTime::getLastErrorsmethod
datetime::DateTime::from_formatdatetime::Messages::to_php
164,000
DateTime::modifymethod
22,000
DateTime::setTimemethod
95,000
DateTimeImmutable::__constructmethod
12333,000
DateTimeImmutable::addmethod
114,000
DateTimeImmutable::formatmethod
8124,000
DateTimeImmutable::getMicrosecondmethod
193,000
DateTimeImmutable::getOffsetmethod
193,000
DateTimeImmutable::getTimestampmethod
193,000
DateTimeImmutable::getTimezonemethod
193,000
DateTimeImmutable::modifymethod
166,000
DateTimeImmutable::setDatemethod
95,000
DateTimeImmutable::setTimezonemethod
215,000
DateTimeZone::__constructmethod
429,000
—
date()
753,000
date_parse()
15511,000
—
gmdate()
12,000
microtime()
1—
strtotime()
268,000
time()
1—

Regular expressions

PHP's PCRE functions: preg_match, preg_match_all, preg_replace, preg_split and preg_quote, on PCRE2 10.44 with its JIT, the library and version PHP 8.5 bundles.

PHPRustCasesFuzzQuirksUsed by
preg_last_error()
8421,000
preg_match()
9729,000
preg_match_all()
1415,000
preg_quote()
53,000
preg_replace()
1215,000
preg_split()
813,000

URLs

parse_url and the PHP 8.5 URI extension (Uri\Rfc3986\Uri).

PHPRustCasesFuzzQuirksUsed by
Uri\Rfc3986\Uri::getHostmethod
2115,000
Uri\Rfc3986\Uri::getRawHostmethod
2115,000
Uri\Rfc3986\Uri::getRawPasswordmethod
2115,000
Uri\Rfc3986\Uri::getRawPathmethod
2115,000
Uri\Rfc3986\Uri::getRawQuerymethod
2115,000
Uri\Rfc3986\Uri::getRawSchememethod
2115,000
Uri\Rfc3986\Uri::getRawUserInfomethod
2115,000
Uri\Rfc3986\Uri::getRawUsernamemethod
2115,000
Uri\Rfc3986\Uri::getSchememethod
2115,000
Uri\Rfc3986\Uri::parsemethod
2115,000
parse_url()
3514,000

Filters

filter_var(): the validation filters (FILTER_VALIDATE_INT, BOOL, FLOAT, REGEXP, URL, EMAIL, IP, MAC, DOMAIN), the sanitizing filters (FILTER_DEFAULT/FILTER_UNSAFE_RAW, FILTER_SANITIZE_*) and FILTER_CALLBACK, with their flags and options, ported from ext/filter (logical_filters.c, sanitizing_filters.c, callback_filter.c, filter.c) of PHP 8.5.

Network

Network helpers: inet_pton/inet_ntop.

PHPRustCasesFuzzQuirksUsed by
inet_ntop()
94,000
inet_pton()
108,000

Serialization

serialize, unserialize and var_export, in PHP 8.5's formats.

PHPRustCasesFuzzQuirksUsed by
igbinary_serialize()
306,230
igbinary_unserialize()
49—
serialize()
159,000
unserialize()
8814,000
var_export()
105,000

YAML

yaml_parse() (ext-yaml 2.3 over libyaml 0.2.5) with the default ini settings: timestamps, !!binary and !php/object stay strings.

PHPRustCasesFuzzQuirksUsed by
yaml_parse()
108,000

Paths

Path functions.

PHPRustCasesFuzzQuirksUsed by
basename()
146,000
fnmatch()
109,000
pathinfo()
83,000

Random numbers

Random numbers: PHP's Mersenne Twister, the engine behind mt_rand(), rand(), array_rand() and shuffle().

PHPRustCasesFuzzQuirksUsed by
array_rand()
31,000
mt_rand()
52,300
mt_srand()
52,300