Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to gracefully die?
    primarykey
    data
    text
    <p>So I've just read <a href="http://www.phpfreaks.com/blog/or-die-must-die" rel="nofollow">Why to never use 'or die'.</a></p> <p>I am more confused then ever. I am validating a complicated form and I go though many nested levels of if statements and what not and I am passing a variable to the form which is called $status which can only be 'new' or 'edit'. Then when the user submits the form to be validated again the form passes along the $status value as a hidden field ($_POST). I want to make sure that the user cannot accidentally change this so I want to catch the error should something other than 'new' or 'edit' pass though. (Although I would like to completely eliminate the possibility of the user affecting this variable in an ideal world.)</p> <p>So I figured that I would use DIE() in an if statement</p> <pre><code>&lt;nested ifs&gt; Select ($status){ Case 'edit': break; Case 'new': break; default: //using example from article trigger_error("An error that should not occur has occurred", E_USER_ERROR); break; } &lt;/nested ifs&gt; </code></pre> <p>I don't really understand how this is cleaner than die()? Essentially I would like to call another function which displays the user some options of what they can do at this juncture to fix the error, but I want the code to absolutely stop running as I don't want an if statement further down to continue parsing anything and generating an error when it finds something other than 'new' or 'edit'.</p> <p>I'm not sure how clear I am so please feel free to ask me to elaborate on any unclear points. (or better yet, can a hidden user field get hacked? How to prevent? :P)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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