Created
May 16, 2022 19:21
-
-
Save jakebathman/c35afa12db081560d949550a8b303372 to your computer and use it in GitHub Desktop.
How long can a PHP function name be?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// How long can a function name in PHP get? | |
$alpha = 'abcdefghijklmnopqrstuvwxyz'; | |
// Note: PHP will run out of memory if you make this range too large | |
for ($i = 1; $i <= 10000; $i++) { | |
$name = str_pad('', $i, $alpha); | |
$count = strlen($name); | |
eval('function ' . $name . "() { echo '{$count}' . PHP_EOL; }"); | |
$name(); | |
} | |
echo "Final name:\n{$name}\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment