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

前端 未结 5 2497
旧巷少年郎
旧巷少年郎 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:52

    If code is repetitive, arrays and (foreach) loops neaten things. You need to decide if the "animal" concept in your code is repetitive or not, or if the code needs to dig in to the uniqueness of each member.

    If I have to repeat myself more than once, I loop.

提交回复
热议问题