3v4l.org

run code in 300+ PHP versions simultaneously
<?php # It is NOT OK to start reading past the end of the string, no, no. Bad programmer. var_dump(substr("a", 1)); # But it is OK to ask for a bigger slice than the length of the string. var_dump(substr("a", 0, 10)); # It is also OK to read past the begining of the string, why not. var_dump(substr("a", -1)); var_dump(substr("a", -2)); # On the other hand, it is NOT OK to stop reading before the end of the string. Bad programmer. var_dump(substr("a", 0, -2));
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
string(0) "" string(1) "a" string(1) "a" string(1) "a" string(0) ""
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
string(0) "" string(1) "a" string(1) "a" string(1) "a" bool(false)
Output for 5.2.7 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
bool(false) string(1) "a" string(1) "a" string(1) "a" bool(false)
Output for 5.2.2 - 5.2.6
bool(false) string(1) "a" string(1) "a" bool(false) bool(false)
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.1
bool(false) string(1) "a" string(1) "a" string(1) "a" string(0) ""

preferences:
142.48 ms | 412 KiB | 5 Q