🍣 PHP 8.3 Coming Soon: json_validate()

Tom Smykowski
3 min readFeb 28, 2023

Should I write articles about PHP? Or you’d prefer me writing about Rust, Go, Javascript, and others? Let me know!

PHP 8.2.3 was released on February, 14, while with time passing by we are closer and closer to the next important version of PHP 8.3.

Yesterday the team “leaked” an information about a feature that got an overwhelmingly positive response from the community and will become a part of the PHP standard library.

In August Juan Carlos Morales proposed adding a new function that will validate if a string is a proper JSON.

Don’t forget to subscribe!

As he motivated his initiative:

Most userland implementations use json_decode() which by design generates a ZVAL(object/array/etc.) while parsing the string, ergo using memory and processing that could be save.

In fact the only real way you could test validity of a JSON string so far was to call json_decode() that constructed a JSON object based on your string. While doing it the function indeed offered errors when the JSON was malformed. But eventually you also ended up having the actual object that occupied unnecessarily the memory.

--

--

Tom Smykowski

Software Engineer & Tech Editor. Top 2% on StackOverflow, 3mil views on Quora. Won Shattered Pixel Dungeon.