Skip to content

How are arrays handled? #23

@carstingaxion

Description

@carstingaxion

I'm not sure this is a bug or wrong use on my side.

I try to use vendor/bin/extract-wp-hooks.php on the following code, which follows the PHP Documentation Standards from the Coding Standards Handbook especially 1.1 Parameters That Are Arrays.

/**
 * Filter term arguments before creating the term.
 *
 * @since 0.1.0
 *
 * @param array $args {
 *     Term arguments.
 *
 *     @type string                $name      Term name.
 *     @type string                $slug      Term slug.
 *     @type int                   $parent    Parent term ID.
 *     @type string                $taxonomy  Taxonomy name.
 *     @type int                   $level     Hierarchy level (1-6).
 *     @type array<string, string> $location  Full location data array.
 * }
 */
$term_args = apply_filters(
	'gatherpress_location_hierarchy_term_args',
	array(
		'name'     => $name,
		'slug'     => $slug,
		'parent'   => $parent_id,
		'taxonomy' => $taxonomy,
		'level'    => $level,
		'location' => $location,
	)
);

But I get an error.

vendor/bin/extract-wp-hooks.php
Loading /shared/httpd/gatherpress/repositories/gatherpress-venue-hierarchy/.extract-wp-hooks.json
Scanning /shared/httpd/gatherpress/repositories/gatherpress-venue-hierarchy

Fatal error: Uncaught Error: [] operator not supported for strings in /shared/httpd/gatherpress/repositories/gatherpress-venue-hierarchy/vendor/akirk/extract-wp-hooks/class-wphookextractor.php:354
Stack trace:
#0 /shared/httpd/gatherpress/repositories/gatherpress-venue-hierarchy/vendor/akirk/extract-wp-hooks/class-wphookextractor.php(135): WpHookExtractor->parse_docblock('/**\n\t\t * Filter...', Array)
#1 /shared/httpd/gatherpress/repositories/gatherpress-venue-hierarchy/vendor/akirk/extract-wp-hooks/class-wphookextractor.php(451): WpHookExtractor->extract_hooks_from_file('/shared/httpd/g...', 'includes/classe...')
#2 /shared/httpd/gatherpress/repositories/gatherpress-venue-hierarchy/vendor/akirk/extract-wp-hooks/extract-wp-hooks.php(55): WpHookExtractor->scan_directory('/shared/httpd/g...')
#3 /shared/httpd/gatherpress/repositories/gatherpress-venue-hierarchy/vendor/bin/extract-wp-hooks.php(18): include('/shared/httpd/g...')
#4 {main}
  thrown in /shared/httpd/gatherpress/repositories/gatherpress-venue-hierarchy/vendor/akirk/extract-wp-hooks/class-wphookextractor.php on line 354

The only way to circumvent the error, is when I set the (documentation) array to have just one value, with no matter, which one.

/**
 * Filter term arguments before creating the term.
 *
 * @since 0.1.0
 *
 * @param array $args {
 *     1 OUT OF 6 Term arguments.
 *
 *     @type int                   $level     Hierarchy level (1-6).
 * }
 */
$term_args = apply_filters(
	'gatherpress_location_hierarchy_term_args',
	array(
		'name'     => $name,
		'slug'     => $slug,
		'parent'   => $parent_id,
		'taxonomy' => $taxonomy,
		'level'    => $level,
		'location' => $location,
	)
);

Is this a bug or misuse on my side?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions