Ticket #3450 (closed enhancement: wontfix)

Opened 2 years ago

Last modified 1 week ago

wp_return() function for echo/return logic

Reported by: markjaquith Assigned to: 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

wp_return.diff (3.9 kB) - added by markjaquith on 12/07/06 04:44:02.
Patch for trunk
wp_return2.diff (3.9 kB) - added by Viper007Bond on 12/07/06 06:56:03.
Was missing a tab

Change History

12/07/06 04:44:02 changed by markjaquith

  • attachment wp_return.diff added.

Patch for trunk

12/07/06 06:54:55 changed by Viper007Bond

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

12/07/06 06:56:03 changed by Viper007Bond

  • attachment wp_return2.diff added.

Was missing a tab

(in reply to: ↑ description ) 01/06/07 21:45:14 changed by xmarcos

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;
}

01/07/07 02:17:54 changed by matt

  • milestone changed from 2.1 to 2.2.

03/27/07 00:01:08 changed by foolswisdom

  • milestone changed from 2.2 to 2.3.

04/24/07 02:26:54 changed by rob1n

function wp_return( $what, $echo = true ) {
	if ( $echo ) {
		echo $what;
	} else {
		return $what;
	}
}

08/14/07 16:27:42 changed by Nazgul

  • keywords changed from has-patch 2nd-opinion to needs-patch 2nd-opinion.
  • milestone changed from 2.3 (trunk) to 2.4 (future).

12/09/07 12:54:00 changed by DD32

  • 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.

12/09/07 21:57:17 changed by Viper007Bond

Better code (I think this works):

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

01/06/08 07:47:42 changed by darkdragon

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

06/26/08 10:47:17 changed by pishmishy

  • status changed from new to closed.
  • resolution set to wontfix.
  • milestone deleted.