Think of Payment here like a signal or “contract” that indicates that any class which “implements” this interface must declare certain members/functions. For example, the class CreditCard implements the Payment interface. Meaning, that the class CreditCard “must” declare a public method called charge that takes in an amount.
Why is this needed? Well, imagine you also have a class called “DebitCard” and another one called “BankAccount”. These are different classes right with possibly much different concepts right? Well, if they all implement the “Payment” interface, they are all guaranteed to have a
charge method with them. This means a function or some other algorithm can loop through credit cards, debit cards, bank account classes and treat them the same with regard to having a charge method.
You may not always know the types of classes you are dealing with. Is $item a credit card or a debit card? Could it be a bank account? We don’t know, but as long as they all implement a payment interface we know they are all going to have a charge method so we can use
$item->charge(100) without caring what type of object it is.
This is tied to an advanced system design concept called “Polymorphism”. If you would like to know more about how this works, I suggest you read up on that topic and its relation to Interfaces. I hope this helps clarify things a bit more.
As for the OP…
Yes reading other people’s code is always a good idea to learn more. You learn how they break down a problem, you see their good habits (and their bad, which you can learn from) and it will always introduce you to new thoughts and ideas. Always be aware that how they solve a problem is not always the right or best solution. It is just “a solution”. To learn more I would suggest you keep exposing yourself to different articles, tutorials and using different mediums like Videos, books, magazines etc. But don’t just read and listen, practice. Write your own programs. Take someone else’s program and make it better. Get involved in a Github project and contribute. Hands on learning with code, finding bugs, reading error messages etc. will always pay off dividends in the end.
And one last thing to keep in mind, you will always have something you can learn. Languages change, technologies evolve and new concepts are explored. I for one have been developing with PHP for over 15 years and programming in general for over 23 years. I am still finding out new stuff. Good luck on the continued learning!