TheJoey Posted September 20, 2009 Share Posted September 20, 2009 im trying to write a function for my shopping cart so i can output totalcost in my order form. function GetTotal() { return $this->totalsub() + $this->shipping(); } that's the function im using at the moment, how can i make it so, i can store it in a variable for latter use, unless i echo the whole function Quote Link to comment https://forums.phpfreaks.com/topic/174868-solved-function-issues/ Share on other sites More sharing options...
Handy PHP Posted September 20, 2009 Share Posted September 20, 2009 function GetTotal() { return $this->totalsub() + $this->shipping(); } $total = GetTotal(); I hope this is what you needed, Handy PHP Quote Link to comment https://forums.phpfreaks.com/topic/174868-solved-function-issues/#findComment-921575 Share on other sites More sharing options...
TheJoey Posted September 20, 2009 Author Share Posted September 20, 2009 thank you yer i wasnt sure about how to go about it. Quote Link to comment https://forums.phpfreaks.com/topic/174868-solved-function-issues/#findComment-921576 Share on other sites More sharing options...
TheJoey Posted September 20, 2009 Author Share Posted September 20, 2009 Fatal error: Using $this when not in object context in C:\xampplite\htdocs\SHOPPINGCART EXAMPLES\ppal\functions\functions.php on line 59 i doesnt seem to be able to grab the total cost from the other page. Quote Link to comment https://forums.phpfreaks.com/topic/174868-solved-function-issues/#findComment-921582 Share on other sites More sharing options...
trq Posted September 20, 2009 Share Posted September 20, 2009 Is this function part of a class? Can we see it? Quote Link to comment https://forums.phpfreaks.com/topic/174868-solved-function-issues/#findComment-921590 Share on other sites More sharing options...
RussellReal Posted September 20, 2009 Share Posted September 20, 2009 $this is for classes/objects, if you are looking to use globals try using the $GLOBALS Quote Link to comment https://forums.phpfreaks.com/topic/174868-solved-function-issues/#findComment-921685 Share on other sites More sharing options...
TheJoey Posted September 20, 2009 Author Share Posted September 20, 2009 well im using classes for my shoppingcart, and just looking for a way to hand the total cost to the next page. Quote Link to comment https://forums.phpfreaks.com/topic/174868-solved-function-issues/#findComment-921748 Share on other sites More sharing options...
trq Posted September 20, 2009 Share Posted September 20, 2009 And you are stuck where? Quote Link to comment https://forums.phpfreaks.com/topic/174868-solved-function-issues/#findComment-921925 Share on other sites More sharing options...
redarrow Posted September 20, 2009 Share Posted September 20, 2009 Can we see the class please so we can help cheers. we are all guess because you ant showing are you? Quote Link to comment https://forums.phpfreaks.com/topic/174868-solved-function-issues/#findComment-921928 Share on other sites More sharing options...
TheJoey Posted September 21, 2009 Author Share Posted September 21, 2009 $this is for classes/objects, if you are looking to use globals try using the $GLOBALS this worked a charm sorry guys its not my code, its for a friend. Quote Link to comment https://forums.phpfreaks.com/topic/174868-solved-function-issues/#findComment-922122 Share on other sites More sharing options...
trq Posted September 21, 2009 Share Posted September 21, 2009 Your not actually saying your using $GLOBALS within your objects are you? Why bother with objects at all? Quote Link to comment https://forums.phpfreaks.com/topic/174868-solved-function-issues/#findComment-922125 Share on other sites More sharing options...
ozestretch Posted September 21, 2009 Share Posted September 21, 2009 Your not actually saying your using $GLOBALS within your objects are you? Why bother with objects at all? No, I believe he is saying his friend is Quote Link to comment https://forums.phpfreaks.com/topic/174868-solved-function-issues/#findComment-922142 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.