Welcome Guest, Not a member yet? Register   Sign In
isset - Message: Trying to get property of non-object
#1

[eluser]mflammia[/eluser]
Hi,

Im trying to test in my view against objects that may not be present to check or uncheck radio buttons, with something like the below:

Code:
if (isset($person)){
echo 'first if';
                if ($person->first_name == '1')
echo 'second if';
                    {echo "checked=\"yes\"";    
                    }
            }

I get the following error:

Code:
A PHP Error was encountered


Severity: Notice

Message: Trying to get property of non-object

I beleive I am testing the present of the object with the isset function correctly so no sure why its still erroring. I put in a couple of echos within the if's to see if they test true but neither message echos? - Sure its a newbie error but any pointers would be much appreciated, thanks.
#2

[eluser]mflammia[/eluser]
Just to add to this after a little more testing, if I either change the

Code:
isset

to

Code:
!isset

or remove

Code:
if ($person->first_name == '1')

I don't get the error, but it then does not function as I wish?
#3

[eluser]Aken[/eluser]
isset() checks to see if the variable is, well, set to something. It can be just about ANYTHING.

Code:
$var = false;
var_dump(isset($var)); // bool(true)

Your $person variable is probably set to something other than an object. If you want to test for an object, use is_object().
#4

[eluser]mflammia[/eluser]
Thats amazing that sorted it, thank you for the reply, have been struggling with that one for ages - didn't know a is_object() even existed, possibly because I still have a long way to go :-)




Theme © iAndrew 2016 - Forum software by © MyBB