3v4l.org

run code in 300+ PHP versions simultaneously
<?php function checkParameters(string $sql) { $countNamed = 0; $countUnnamed = 0; $inQuote = false; for ($i = 0; $i < strlen($sql); ++ $i) { if ($inQuote) { if ($sql[$i] == $quote) { $inQuote = false; continue; } } else { if (in_array($sql[$i], ['"', "'"])) { $quote = $sql[$i]; continue; } } if ($sql[$i] == ':') { $countUnnamed ++; } elseif ($sql[$i] == '?') { $countNamed ++; } } if ($countNamed && $countUnnamed) { throw new Exception("mixed parms in: $sql" . PHP_EOL); } } $sql = "SELECT a, b FROM someTable WHERE a = '?' AND b = :id"; // checkParameters($sql); $sql = "SELECT a, b FROM someTable WHERE a = ? AND b = :id"; // checkParameters($sql); $sql = "SELECT a, b FROM someTable WHERE a = '?' AND b = :id"; checkParameters($sql);
Output for 7.1.25 - 7.1.28, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.30, 8.0.0 - 8.0.22, 8.1.0 - 8.1.9
Fatal error: Uncaught Exception: mixed parms in: SELECT a, b FROM someTable WHERE a = '?' AND b = :id in /in/Rc7B6:32 Stack trace: #0 /in/Rc7B6(44): checkParameters('SELECT a, b FRO...') #1 {main} thrown in /in/Rc7B6 on line 32
Process exited with code 255.

preferences:
52.07 ms | 410 KiB | 5 Q