The Little Guy Posted May 1, 2008 Share Posted May 1, 2008 myClass.php: <?php class myClass { public $myVar = ''; function myFunction($value){ return $myVar = $value; } function useVars(){ echo $myVar; } } ?> <?php include 'myClass.php'; $tempC = new myClass(); $tempC->myFunction('I am a cat'); $tempC->useVars(); ?> After running this file, the output would be blank why? Link to comment https://forums.phpfreaks.com/topic/103727-solved-no-output/ Share on other sites More sharing options...
conker87 Posted May 1, 2008 Share Posted May 1, 2008 Return values in functions, don't echo them! <?php class myClass { public $myVar = ''; function myFunction($value){ return $myVar = $value; } function useVars(){ return $myVar; } } ?> Link to comment https://forums.phpfreaks.com/topic/103727-solved-no-output/#findComment-531095 Share on other sites More sharing options...
The Little Guy Posted May 1, 2008 Author Share Posted May 1, 2008 it still does nothing Link to comment https://forums.phpfreaks.com/topic/103727-solved-no-output/#findComment-531102 Share on other sites More sharing options...
PFMaBiSmAd Posted May 1, 2008 Share Posted May 1, 2008 return $myVar = $value; should be - $this->myVar = $value; Link to comment https://forums.phpfreaks.com/topic/103727-solved-no-output/#findComment-531104 Share on other sites More sharing options...
The Little Guy Posted May 1, 2008 Author Share Posted May 1, 2008 would I do this->$myVar to set the variable to the new value? Link to comment https://forums.phpfreaks.com/topic/103727-solved-no-output/#findComment-531105 Share on other sites More sharing options...
PFMaBiSmAd Posted May 1, 2008 Share Posted May 1, 2008 You also need to change - echo $myVar; to this - echo $this->myVar; Link to comment https://forums.phpfreaks.com/topic/103727-solved-no-output/#findComment-531113 Share on other sites More sharing options...
The Little Guy Posted May 1, 2008 Author Share Posted May 1, 2008 This is from the actual file: Fatal error: Cannot access empty property in /home/.marble/ryannaddy/phpsnips.com/phpMagick/phpMagick.php on line 39 <?php class phpMagick { public $input = ''; function set_input($ipt){ return $this->$input = $ipt; // Line 39 } } ?> Link to comment https://forums.phpfreaks.com/topic/103727-solved-no-output/#findComment-531122 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.