WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#12209 closed defect (bug) (invalid)

Syntax errors in filters

Reported by: mfields Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Administration Keywords: filter, variable, syntax
Focuses: Cc:

Description

Could be wrong, but should the "$" be inside the curly braces or does it matter?

Line 536:
$actions = apply_filters("${taxonomy}_row_actions", $actions, $tag);

Line 564:
apply_filters("manage_${taxonomy}_custom_column", , $column_name, $tag->term_id);

https://core.trac.wordpress.org/browser/trunk/wp-admin/includes/template.php

Change History (3)

comment:1 nacin4 years ago

  • Milestone Unassigned deleted

It looks weird, but it works. It's a way to define a variable variable.

$foo = 'bar';
$baz = "${foo}";
var_dump( $baz ); // string(3) "bar"
$baz = "{$foo}";
var_dump( $baz ); // string(3) "bar"

Based on a real quick test, it appears to be a negligible difference in performance.

comment:2 mfields4 years ago

nacin - Thanks for the info! I have never seen anything like this before so was prompted to ask.

comment:3 dd324 years ago

  • Resolution set to invalid
  • Status changed from new to closed

It does look weird at first if you've never seen it. But it is syntactically correct.

It reduces errors too, take this for example:

"${bar}_test"
"{$bar}_test"
"$bar_test"
//Ok, All those look sane, now try:
"${bar_foo_result}_taz"
"{$bar_foo_result}_taz"
"$bar_foo_result_taz"

The braces just make it that much more clearer that the variable name is held within, and that the braces will not appear in the final string..

Note: See TracTickets for help on using tickets.