3v4l.org

run code in 300+ PHP versions simultaneously
<?php //-------------------------------------------------- // Just while the function is re-named if (!function_exists('is_trusted')) { function is_trusted($value) { return is_literal($value); } } //-------------------------------------------------- $limit = trim(' 100 '); // Not trusted $_GET['ids'] = [trim(' 1 '), 2, 3]; var_dump($_GET['ids'][0], is_trusted($_GET['ids'][0])); $ids_untrusted = ( $_GET['ids'] ?? [] ); $ids_trusted = array_map( 'intval', $ids_untrusted ); //-------------------------------------------------- $sql = 'SELECT * FROM foo WHERE id IN (' . implode( ',', $ids_untrusted ) . ')'; // Whoops var_dump($sql, is_trusted($sql)); //-------------------------------------------------- $sql = 'SELECT * FROM foo WHERE id IN (' . implode( ',', $ids_trusted ) . ')'; var_dump($sql, is_trusted($sql)); //-------------------------------------------------- $sql = sprintf( 'SELECT * FROM foo WHERE id IN (%s)', implode( ',', $ids_trusted ) ); var_dump($sql, is_trusted($sql)); //-------------------------------------------------- $sql = sprintf( 'SELECT * FROM foo LIMIT %d', (int)$limit ); var_dump($sql, is_trusted($sql)); ?>
Output for 8.1.23 - 8.1.28, 8.2.10 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught Error: Call to undefined function is_literal() in /in/FvtpW:8 Stack trace: #0 /in/FvtpW(18): is_trusted('1') #1 {main} thrown in /in/FvtpW on line 8
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught Error: Call to undefined function is_literal() in /in/FvtpW:8 Stack trace: #0 /in/FvtpW(18): is_trusted('1') #1 {main} thrown in /in/FvtpW on line 8
Process exited with code 255.

preferences:
56.81 ms | 401 KiB | 27 Q