[eluser]joelkallman[/eluser]
[quote author="Phil Sturgeon" date="1335288445"]Obviously I am not going to half-arse it. [/quote]
Agreed. You and the Reactor Engineers have proven that.
[quote author="Phil Sturgeon" date="1335288445"][quote author="joelkallman" date="1335287734"]As far as returning an array...[/quote]
That is the part where you are going off track and randomly talking about arrays for some reason.
[/quote]
Let me see if I can explain a little clearer.
Code:
// When called without a 'key' passed, this will always return the full array if one exists.
$this->input->post();
// Consistent behavior from PHP to CodeIgniter
// This is what is being proposed in order to maintain consistency
$_POST['key'] === $this->input->post('key') === NULL; // Assuming the key doesn't exist.
$_POST === $this->input->post() === array(); // When no POST data exists. - This is what I am adding to your proposal
// Example code as it exists right now
$post_data = $this->input->post() ? $this->input->post() : array();
foreach ($post_data as $key => $val)
{
// ... Do something
}
// Expected behavior if it follows PHP
foreach ($this->input->post() as $key => $val)
{
// ... Do something
}
I don't know if that makes it any clearer. I want to be able to use the $this->input->post() method in the exact way I would expect to use the $_POST superglobal. If there is a key that doesn't exist, then it returns NULL. If accessing it without a key, it always returns an array, whether it is empty or not. Since we are proposing a change, I don't want to go half way to expected behavior because then we would still be stuck checking the returned value from $this->input->post() to see if it is_array() or something like that.
<b>I understand that you want to keep the scope to just returning NULL as opposed to FALSE, but I feel that scope is too limited in order to justify the change you are proposing. IMHO we should go all the way or stay where we are.</b>
I agree with your code adjustment, if we also make the following change of the code from this:
Code:
function post($index = NULL, $xss_clean = FALSE)
{
// Check if a field has been provided
if ($index === NULL AND ! empty($_POST))
{
$post = array();
// Loop through the full _POST array and return it
foreach (array_keys($_POST) as $key)
{
$post[$key] = $this->_fetch_from_array($_POST, $key, $xss_clean);
}
return $post;
}
return $this->_fetch_from_array($_POST, $index, $xss_clean);
}
... to this...
Code:
function post($index = NULL, $xss_clean = FALSE)
{
// Check if a field has been provided
if ($index === NULL)
{
$post = array();
// Loop through the full _POST array and return it
foreach (array_keys($_POST) as $key)
{
$post[$key] = $this->_fetch_from_array($_POST, $key, $xss_clean);
}
return $post;
}
return $this->_fetch_from_array($_POST, $index, $xss_clean);
}