Skip to content

Instantly share code, notes, and snippets.

@jakebathman
Created May 16, 2022 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakebathman/c35afa12db081560d949550a8b303372 to your computer and use it in GitHub Desktop.
Save jakebathman/c35afa12db081560d949550a8b303372 to your computer and use it in GitHub Desktop.
How long can a PHP function name be?
<?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