Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 0.91 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2.  * The only function of this statement is to return $poll_id if it's set. Which
  3.  * snippet would you use and why?
  4.  *
  5.  * I (@jrtashjian) prefer and wrote snippet 1. I like how contained the
  6.  * function is, and the fact I'm only calling the post() function once.
  7.  *
  8.  * Each snippet works correctly, this is just preference. I find it redundant
  9.  * to call the post() function more than once (as shown in snippet 3). I also
  10.  * find it unnecessary to create a variable ($poll_id) to store the result of
  11.  * function post() when I'll only be using it for the if statement.
  12.  *
  13.  * Let me know on Twitter, @jrtashjian.
  14.  */
  15.  
  16. // Snippet 1
  17. if( $poll_id = $this->EE->input->post('poll_id') )
  18. {
  19.         return $poll_id;
  20. }
  21.  
  22. // Snippet 2
  23. $poll_id = $this->EE->input->post('poll_id');
  24. if( $poll_id )
  25. {
  26.         return $poll_id;
  27. }
  28.  
  29. // Snippet 3
  30. if( $this->EE->input->post('poll_id') )
  31. {
  32.         return $this->EE->input->post('poll_id');
  33. }