ShaolinF Posted December 20, 2009 Share Posted December 20, 2009 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; } } Link to comment https://forums.phpfreaks.com/topic/185793-catchable-fatal-error-object-of-class-stdclass-could-not-be-converted-to-string/ Share on other sites More sharing options...
ChemicalBliss Posted December 20, 2009 Share Posted December 20, 2009 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- Link to comment https://forums.phpfreaks.com/topic/185793-catchable-fatal-error-object-of-class-stdclass-could-not-be-converted-to-string/#findComment-981045 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.