apply_filters/do_action tag characters limit

I always thought that the memory size was the limit for the string length, but according to the PHP documentation:

string can be as large as up to 2GB (2147483647 bytes maximum)

There is also the maximum allowed memory size (memory_limit) for the PHP script, to consider.

Testing: Do not perform this on a production server:

You could always use the str_repeat idea from this answer to test it:

// Check the hook name size limit:

$long_hook_name = str_repeat( 'x', 1024 * 1024 ); // Adjust the size until you hit the roof!

add_action( $long_hook_name, function(){
    echo 'Greetings from the hook with a very long name';
});

do_action( $long_hook_name );

but only test this where it’s safe (locally?) 😉

The same should apply for the add_filter(), since add_action() is just a wrapper:

function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
            return add_filter($tag, $function_to_add, $priority, $accepted_args);
}

according to the source.