1

I'm referring to this question. Is it possible to extract() values from an associative array with hyphens/dashes in their keys by now?

It's about an older version of the WordPress Shortcode API. Example:

function bartag_func( $atts ) {
    extract( shortcode_atts( array(
        'foo-bar' => 'something'
    ), $atts ) );

    return "foo = ${foo-bar}";
}
add_shortcode( 'bartag', 'bartag_func' );
bad_coder
  • 11,289
  • 20
  • 44
  • 72
Ben
  • 1,550
  • 1
  • 16
  • 24
  • 1
    *`smacks forehead`* PHP still hasn't changed the rules on variable naming. If you need the values and you don't need them in variables you can use some other array parsing method. – Jay Blanchard Jun 23 '16 at 19:20

2 Answers2

4

It is still not possible. However, for the PHP.net engine, I have an RFC under discussion that would make it possible in PHP 8.

bishop
  • 37,830
  • 11
  • 104
  • 139
4

shortcode_atts returns an array so just use it.

function bartag_func( $atts ) {
    $params = shortcode_atts( array(
        'foo-bar' => 'something'
    ), $atts ) );

    return "foo = " . $params['foo-bar'];
}
add_shortcode( 'bartag', 'bartag_func' );
Danijel
  • 12,408
  • 5
  • 38
  • 54