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"]?

display-name-is-missing
  • 4,424
  • 5
  • 28
  • 41
gurehbgui
  • 14,236
  • 32
  • 106
  • 178

4 Answers4

3

Should be as simple as:

echo $result->Res;
Sean Bright
  • 118,630
  • 17
  • 138
  • 146
2

$result an object.

So you can do

echo $result->Res;
Ron van der Heijden
  • 14,803
  • 7
  • 58
  • 82
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 :)

laminatefish
  • 5,197
  • 5
  • 38
  • 70
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; 
ALOUI MH
  • 97
  • 1
  • 10