What's the best way to store class variables in PHP?

前端 未结 5 2495
旧巷少年郎
旧巷少年郎 2021-02-20 11:08

I currently have my PHP class variables set up like this:

class someThing {

    private $cat;
    private $dog;
    private $mouse;
    private $hamster;
    pr         


        
5条回答
  •  天涯浪人
    2021-02-20 11:56

    • Use the first method when you know you need that variable.
    • Use the second method (an array collection of variables) when you have dynamic variable needs.

    You can combine these 2 methods, so some variables are hardcoded into your class, while others are dynamic. The hardcoded variables will have preference compared with magic methods.

提交回复
热议问题