How WordPress understands what do with the (all) key in the $wp_filter array? [duplicate]

You have all explained in this function for instance

File: wp-includes/plugin.php
402: /**
403:  * Execute functions hooked on a specific action hook.
404:  *
405:  * This function invokes all functions attached to action hook `$tag`. It is
406:  * possible to create new action hooks by simply calling this function,
407:  * specifying the name of the new hook using the `$tag` parameter.
408:  *
409:  * You can pass extra arguments to the hooks, much like you can with apply_filters().
410:  *
411:  * @since 1.2.0
412:  *
413:  * @global array $wp_filter         Stores all of the filters
414:  * @global array $wp_actions        Increments the amount of times action was triggered.
415:  * @global array $wp_current_filter Stores the list of current filters with the current one last
416:  *
417:  * @param string $tag     The name of the action to be executed.
418:  * @param mixed  $arg,... Optional. Additional arguments which are passed on to the
419:  *                        functions hooked to the action. Default empty.
420:  */
421: function do_action($tag, $arg = '') {
422:    global $wp_filter, $wp_actions, $wp_current_filter;
423: 
424:    if ( ! isset($wp_actions[$tag]) )
425:        $wp_actions[$tag] = 1;
426:    else
427:        ++$wp_actions[$tag];
428: 
429:    // Do 'all' actions first
430:    if ( isset($wp_filter['all']) ) {
431:        $wp_current_filter[] = $tag;
432:        $all_args = func_get_args();
433:        _wp_call_all_hook($all_args);
434:    }
435: 
436:    if ( !isset($wp_filter[$tag]) ) {
437:        if ( isset($wp_filter['all']) )
438:            array_pop($wp_current_filter);
439:        return;
440:    }
441: 
442:    if ( !isset($wp_filter['all']) )
443:        $wp_current_filter[] = $tag;
444: 
445:    $args = array();
446:    if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this)
447:        $args[] =& $arg[0];
448:    else
449:        $args[] = $arg;
450:    for ( $a = 2, $num = func_num_args(); $a < $num; $a++ )
451:        $args[] = func_get_arg($a);
452: 
453:    $wp_filter[ $tag ]->do_action( $args );
454: 
455:    array_pop($wp_current_filter);
456: }

The part:

429:    // Do 'all' actions first

Speaks all has the special treatment inside the hook generator functions.

The similar logic you will find in other hook generator functions:

apply_filters
apply_filters_ref_array
apply_filters_deprecated
do_action
do_action_ref_array
do_action_deprecated

So all has the special treatment.

You may use all for introspection as in here where I list all actions hooks in sequence order for a single WordPress request.


From the comments:

I understand, but I want to know how WordPress understands that when passing this key all it will affect all actions or filters. It should be defined somewhere

Took me some time to understand what you meant. Yes. There is a global called $wp_filter in there all hooks are saved. In case of the example
add_action( 'all', '_20161224_printer' ); here, this will be inside that global.

[all] => WP_Hook Object
        (
            [callbacks] => Array
                (
                    [10] => Array
                        (
                            [_20161224_printer] => Array
                                (
                                    [function] => _20161224_printer
                                    [accepted_args] => 1
                                )

                        )

                )

            [iterations:WP_Hook:private] => Array
                (
                )

            [current_priority:WP_Hook:private] => Array
                (
                )

            [nesting_level:WP_Hook:private] => 0
            [doing_action:WP_Hook:private] => 
        )

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)