Inked Posted May 8, 2015 Share Posted May 8, 2015 Hi. So I'm trying to learn classes and how to use them with PHP and I'm stuck. I'm trying to make a script that takes input from a user of 2 amounts and stores them into variables. I would then like to use these variables in a couple of functions to make some calculations and finally echo my findings. I'm close but I've still got issues and it seems like I'm now running in circles. I've been reading documentation on classes and googling, but I'm quite stuck. I'm hoping for perhaps some explanations. I could do what I need to do in just another php processing script. But I'm really trying to learn classes and how they can be used with other pages and how general they can be. Here's what I got so far: CalculateChange.php http://pastebin.com/ctdkYjXc# class_Change.php http://pastebin.com/gdfYGXwV# Quote Link to comment https://forums.phpfreaks.com/topic/296146-calculating-change-denominations-w-classes/ Share on other sites More sharing options...
Muddy_Funster Posted May 8, 2015 Share Posted May 8, 2015 Well, at a glance you're still strugling with the scope of variables within methods. Your validatePayed and calculateChange methods are refferencing method specific variables $changeDue, $change, $oneHundred, $fifty etc. and from your parameter devleration it looks like you're actually meening to refference the class parameters of the same name which would require the same $this-> prefix that you use to get the values of the paramter varialbes on the right of the assignments. Quote Link to comment https://forums.phpfreaks.com/topic/296146-calculating-change-denominations-w-classes/#findComment-1511140 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.