I'm relatively new to PHP and I have a question about declaring variables in a PHP class. I've been learning about object-oriented programming (OOP) in PHP and I'm a bit confused about when to declare variables within a class.
I understand that variables in a class are called properties, but I'm not sure at which point I should declare them. Should I declare all the variables at the beginning of the class, or should I declare them within each method as I need them?
I've seen examples where all the variables are declared at the beginning of the class, and I've also seen examples where variables are declared directly within methods. I'm not sure which approach is considered best practice or if it depends on the specific use case.
Could anyone shed some light on this for me? I would really appreciate any guidance or explanation you could provide. Thanks in advance!