• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax advice..

#1
[eluser]stormbytes[/eluser]
Evening folks -

What's a quick-and-dirty statement that does the same as the code below, without generating an object-error? I'm trying to find a shortcut that does not require assigning the function output to a variable and then testing the variable.

Code:
if(isset(this->input->post('id')))

#2
[eluser]Shanto[/eluser]
isset function does not require you use $this->input->post. try this:

Code:
if($this->input->post('id'))

#3
[eluser]stormbytes[/eluser]
Well that was my first guess Smile Seeing as If() evaluates a boolean true/false. For some reason it's giving me grief! Time to refactor..

Thanks!

#4
[eluser]Dennis Rasmussen[/eluser]
Do you have a problem with the following?
Code:
if($this->input->post('id'))
If so, what? Smile

#5
[eluser]jalalski[/eluser]
$this->input->post('id') will return false if the POST variable doesn't exist or isn't set, so there is no need to use isset (which anyway doesn't make much sense on the return value of a function as it will always be true).

#6
[eluser]tonanbarbarian[/eluser]
you just need to be aware that the value 0 is also evaluated to false, so if the form value returns a value of 0 it will not process

#7
[eluser]stormbytes[/eluser]
The '0' value was my problem in this particular case... Smile

Thanks for the help!

#8
[eluser]WanWizard[/eluser]
Common PHP pitfall.

The only safe test is
Code:
if ( $this->input->post('field') === FALSE )
{
    // it does not exist
}

#9
[eluser]stormbytes[/eluser]
Heh! Funny that's what I ended up doing. Seems that typecasting the comparison gives you a clean yes/no.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.