Jump to content

Catchable fatal error: Object of class stdClass could not be converted to string


ShaolinF

Recommended Posts

Hi Guys

 

I am trying to return the myVar variable in my class but I keep getting the following error:

 

Catchable fatal error: Object of class stdClass could not be converted to string 

 

Code below:

 

MyClass {

private myVar;

__construct() {
	$this->myVar = 10;
}

get_myvar()
{
	return $this->myVar;
}

}

if that is the code you are missing:

 

"Class" decleration:

should be "Class MyClass"

 

"Function" Declerations:

Should be "Function __construct" "Function get_myvar"

 

and your missing the dollar symbol in front of your class property:

should be "private $myVar"

 

Then this should work:

 

<?php

Class MyClass {

   private $myVar;

   function __construct() {
      $this->myVar = 10;
   }

   function get_myvar()
   {
      return $this->myVar;
   }

}

$myclass = New MyClass();
echo($myclass->get_myvar());

?>

 

Hope this helps,

-CB-

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.