I want the method to add two values, but occasionally there are more than two values and in this case they will be in the form of an array. The idea is to total the values in the array when it has values assigned to it.
I did think about just using an array regardless of the number of values and adding the values in the array. Perhaps there is a case to be made for a method that totals the values in an array instead of relying on the add method?
I think your instincts are good about placing all of the values you want to sum up into an array. That would be the expected design pattern. And you don't need OOP for this at all. You can use array_sum() to get the answer in a single instruction.
In particular, try to stay away from internet examples. The "good work" in PHP OOP design and programming is being done in systems like Laravel, and it's all very, very new in PHP. An unfortunately large amount of really bad PHP code is lying around on the internet, so check the publication dates and steer yourself away from anything more than a year or two old.
Ray Paseur
For anyone who comes across this question in the future, please take note of the author's statement here:
Perhaps there is a case to be made for a method that totals the values in an array instead of relying on the add method?
The solution is found in using array_sum(), a PHP built-in function. No other code is needed at all.
If you're interested in learning PHP object-oriented programming, start your adventure here:
http://php.net/manual/en/language.oop5.php
In particular, try to stay away from internet examples. The "good work" in PHP OOP design and programming is being done in systems like Laravel, and it's all very, very new in PHP. An unfortunately large amount of really bad PHP code is lying around on the internet, so check the publication dates and steer yourself away from anything more than a year or two old.