Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When dealing with arrays I'll usually favour array_key_exists('suggested_only', $_GET) over isset($_GET['suggested_only'])</p> <p>If there's nothing really different with the execution of the data, just a difference in the data you are selecting, I'd put your statement at the TOP of the API page, not the bottom.</p> <p>That way, your IF statement can define a flag for when you inevitably call $shopper->get_lists()</p> <p>You could do something like this:</p> <pre><code>$suggestions = false; $clobber = false; if(isset($_GET['suggested_only']) &amp;&amp; $_GET['suggested_only'] == 'true') { $suggestions = true; } ... $shopper_lists = $shopper-&gt;get_lists($clobber, $suggestions); </code></pre> <p>This way, you don't really duplicate code fetching the data you want.</p> <p>HOWEVER</p> <p>When it comes down to it, what if you add a whole series of types of lists to get. You don't want to add a flag and another variable to your get_lists function. It would become a mess.</p> <p>It would be better to have a single variable like $_GET['type'], and switch it as follows:</p> <pre><code>switch($_GET['type']) { case 'thingo': $shopper-&gt;get_lists('thingo'); //Or you could use $shopper-&gt;get_thingo_list(); break; case 'suggestion': $shopper-&gt;get_lists('suggestion'); //Or you could use $shopper-&gt;get_suggestion_list(); break; case 'list': $shopper-&gt;get_lists('list'); //Or you could use $shopper-&gt;get_list(); break; default: //No type exists here break; } </code></pre> <p>Some people might suggest to just pass the $_GET variable straight to your function, but I always get a bit nervous doing that for security reasons.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload