Opened 6 years ago

Closed 5 years ago

#3450 closed enhancement (wontfix)

wp_return() function for echo/return logic

Reported by: markjaquith Owned by: anonymous
Priority: low Milestone:
Component: Administration Version: 2.1
Severity: minor Keywords: needs-patch 2nd-opinion
Cc:

Description

Elegant echo/return logic wrapper by Andy Skelton

Look at all the red in the patch!

// Implementation within function:  return wp_return($func_data, $echo_flag);
function wp_return($data, $echo = true) {
	echo ( $echo ) ? $data : '';
	return $data;
}

Attachments (2)

wp_return.diff (3.9 KB) - added by markjaquith 6 years ago.
Patch for trunk
wp_return2.diff (3.9 KB) - added by Viper007Bond 6 years ago.
Was missing a tab

Download all attachments as: .zip

Change History (12)

Patch for trunk

Just though I'd point out that this isn't the same as the code as the code it replaces (this new function always returns something, even if it echo's it first).

Not saying this is bad (I personally think it's good as you can see what a function echo'ed), just pointing out the difference.

+1

Was missing a tab

comment:2 in reply to: ↑ description   xmarcos6 years ago

Replying to markjaquith:

Elegant echo/return logic wrapper by Andy Skelton

Look at all the red in the patch!

// Implementation within function:  return wp_return($func_data, $echo_flag);
function wp_return($data, $echo = true) {
	echo ( $echo ) ? $data : '';
	return $data;
}

As Viper007Bond says, this is wrong, it will always produce and echo and then return the same value.

The function should be as follows,

function wp_return($data, $echo = true) {
	if ($echo) :
		echo $data;
	else :
		return $data;
	endif;
}

comment:3   matt6 years ago

  • Milestone changed from 2.1 to 2.2
  • Milestone changed from 2.2 to 2.3
function wp_return( $what, $echo = true ) {
	if ( $echo ) {
		echo $what;
	} else {
		return $what;
	}
}
  • Keywords needs-patch added; has-patch removed
  • Milestone changed from 2.3 (trunk) to 2.4 (future)

comment:7   DD325 years ago

  • Milestone changed from 2.4 to 2.5

While i think this is a good idea, There doesnt seem much traction on implementing this, I'm going to set it to 2.5 for now, Feel free to move back to 2.4 if someone wants to do it.

Better code (I think this works):

function wp_return( $what, $echo = true ) {
	( $echo ) ? echo $what : return $what;
}

Is this worth implementing? If not then just close as won't fix.

  • Milestone 2.6 deleted
  • Resolution set to wontfix
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.