0

I have the following var_dump($result):

 object(stdClass)#2 (1) {
  ["Res"]=>
  string(3) "foo"
}

and I dont know how to print the "Res". I tired the following: echo $result["Res"] and get:

Fatal error: Cannot use object of type stdClass as array in [...] on line 30

How to print the content of ["Res"]?

1

4 Answers 4

3

Should be as simple as:

echo $result->Res;
0
2

$result an object.

So you can do

echo $result->Res;
1

As has been stated already. You can access this very simple object like so:

$result->Res;

However, if you had various other elements/objects within, then you'd access each one as follows:

$result->{elementname}->fieldname;

Just in case you want to go a bit further with it :)

1

stdClass is an object , you can't user the echo function with an objector table ... you have to use a method to view Res:

echo $result->Res;

or if it's inside a class better use

return $result->Res; 

Not the answer you're looking for? Browse other questions tagged or ask your own question.