[eluser]Phil Sturgeon[/eluser]
CodeIgniter has always had a history of being backwards compatible with releases and this is what makes it one of the most used frameworks around. Some strive to constantly be the best by rewriting themselves and breaking their API, some even do total recodes. None of these approaches are neccessairily wrong, but they get a different crowd of developers.
Recently the biggest change between 1.7.x and 2.x was adding in a prefix to some classes, and between 2.0.x and 2.1.x was even less than that. It's always been easy, and the fact that I can bring a codebase that is 4 years old up to date in no time is a blessing.
It's because of this that some changes are hard to decide on, even if they would be "for the best". This proposed change is that the following methods should return NULL instead of FALSE:
Code:
$this->input->get();
$this->input->get_post();
$this->input->post();
$this->input->cookie();
$this->input->server();
$this->input->post();
$this->session->userdata();
$this->session->flashdata();
Why do this? Does it matter? Well yes, while at first glance it appears trivial it has two benefit; When these items do not know what a value is (because none was provided) they should say NULL. By instead providing FALSE we are actually getting a value, and so when we try to save this in a SQL database the PHP drivers convert FALSE to 0, and we end up with 0 in our database! That is pretty annoying.
Now we can do checks for each of these every time, but they are a pain in the backside.
Code:
// 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');
Compatibility
If this change were to be made, you may well find that the majority of your code is absolutely fine.
Example:
Code:
if ($this->input->post('neverset') == FALSE)
if ( ! $this->input->post('neverset'))
Both of those statements will still work just fine, as FALSE == NULL. You would only notice a problem if you had used:
Code:
if ($this->input->post('neverset') === FALSE)
That would be fail to match, as FALSE !== NULL.
Thoughts
I'm writing this post not to tell you what I plan on doing, as that's not how us Engineer types roll! We are part of the community and want to work WITH you guys for the best. I put out a Tweet and 90% of the feedback was positive, with 5% sounding confused about the benefits (explained better above now) and 5% giving odd answers I can barely associate with any form of reason.
I would appreciate feedback on this, so we can see how to move forwards, or I can throw the idea out the window. I'd rather not have to do that, as NULL is the correct way to do things. At some point we will need to do it correctly, and now rather in a year would be a much better idea.