Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Created April 23, 2012 16:27
Show Gist options
  • Save philsturgeon/2472086 to your computer and use it in GitHub Desktop.
Save philsturgeon/2472086 to your computer and use it in GitHub Desktop.
Dealing with CodeIgniter's incorrect defaults
/*/*
* CodeIgniter likes to return FALSE instead of NULL, which means
* that you need to check for FALSE before sending things of to
* the DB - amonsgt other issues - as well as the fact that FALSE
* is actually a value and not a valid "I dont know" response.
*/
// NULL default in PHP 5.3
$foo = $this->input->post('foo') ?: NULL;
// NULL default in PHP 5.2
$foo = $this->input->post('foo') ? $this->input->post('foo') : NULL;
// NULL default proposal in CodeIgniter 3.0
$foo = $this->input->post('foo');
/*
* Seems trivial, but this is how pretty much everyone else in all of
* PHP land does it.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment