frozenmafia Posted June 9, 2010 Share Posted June 9, 2010 Thanks pal but now I get: Fatal error: Using $this when not in object context in /home/frozen01/public_html/classeswgradients.php on line 777. 776 /*** a line of text ***/ 777 $text = $this->username; Link to comment https://forums.phpfreaks.com/topic/204306-using-this/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 9, 2010 Share Posted June 9, 2010 Using $this when not in object context You cannot use $this-> unless you are in a class/object. Is the code you posted part of a class? Link to comment https://forums.phpfreaks.com/topic/204306-using-this/#findComment-1070013 Share on other sites More sharing options...
frozenmafia Posted June 9, 2010 Author Share Posted June 9, 2010 yeah it is in a classes.php where everything works off. It works everywhere else in the code Link to comment https://forums.phpfreaks.com/topic/204306-using-this/#findComment-1070019 Share on other sites More sharing options...
Psycho Posted June 9, 2010 Share Posted June 9, 2010 yeah it is in a classes.php where everything works off. It works everywhere else in the code That really doesn't answer the question. Just because the file is named classes.php doesn't mean anything. Is that line in a properly declared CLASS. Example: <?php class Time { var $sTime; function GenerateCurrentTime(){ $this->sTime = gmdate("d-m-Y H:i:s"); return $this->sTime; } } ?> Link to comment https://forums.phpfreaks.com/topic/204306-using-this/#findComment-1070033 Share on other sites More sharing options...
frozenmafia Posted June 9, 2010 Author Share Posted June 9, 2010 in that case, no it isn't other than username been declared BEFORE the function and it works everywhere else. Link to comment https://forums.phpfreaks.com/topic/204306-using-this/#findComment-1070046 Share on other sites More sharing options...
Alex Posted June 9, 2010 Share Posted June 9, 2010 Post your code. Link to comment https://forums.phpfreaks.com/topic/204306-using-this/#findComment-1070068 Share on other sites More sharing options...
Daniel0 Posted June 9, 2010 Share Posted June 9, 2010 Link to comment https://forums.phpfreaks.com/topic/204306-using-this/#findComment-1070071 Share on other sites More sharing options...
frozenmafia Posted June 9, 2010 Author Share Posted June 9, 2010 ok [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/204306-using-this/#findComment-1070093 Share on other sites More sharing options...
Alex Posted June 9, 2010 Share Posted June 9, 2010 As suspected, your problem is a scope problem. You're trying to use $this inside of the gradient function, it is not defined there. Read about variable scopes here. Why are you even using OOP in the first place? You're not using it in any way shape or form that would give you an advantage. It's a horrible implementation, all you're doing is packing everything inside the constructor of the object. Link to comment https://forums.phpfreaks.com/topic/204306-using-this/#findComment-1070103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.