http_build_query() And Enumerations¶
<?php
enum e : string {
case A = 'a';
}
print http_build_query(['a' => 'A', 'b' => e::A]);
// PHP 8.4 and more recent : a=A&b=a
// Pre PHP 8.4 : a=A&b%5Bname%5D=A&b%5Bvalue%5D=a a=A&b[name]=A&b[value]='a'
When using a backed enum with http_build_query(), the PHP native function uses the value of the case, and not the case itself. This is very convenient to output a compatible value, instead of an internal object. This is valid since PHP 8.4.
See Also¶
http_build_query and enum [Try me]
PHP Features¶
Last updated: 14 July 2026