PHP相当于ObservableCollection <t> / List <t>?

时间:2016-06-14 14:55:57

标签: php class

在C#中,我可以创建一个类Monster

public class Monster
{
    public string name;
    public bool mean;

    public Monster(string monsterName, bool isMean){
            name = monsterName;
            mean = isMean;
    }
}

然后我可以创建一个以某种方式添加怪物的observableCollectionList

public class MonsterMash
{
    public static List<Monster> MonsterMashList(){
        var temp = new List<Monster>();
        temp.Add(new Monster("Frankenstein", true));
        temp.Add(new Monster("Mr.Hyde", true));
        return temp;
    }
}

有没有更好的方法在PHP中创建类似的构造,同时确保只添加怪物?目前,我的实施如下:

public class Monster 
{
    public $name;
    public $mean;

    function __construct($monsterName, $isMean) {
        $this->name = $monsterName;
        $this->mean = $isMean;
    }
}

public class MonsterMash
{
    public static MonsterMashList
    {
        $temp = = array();
        array_push(new Monster("Frankenstein", true));
        array_push(new Monster("Mr.Hyde", true));
        return $temp;
    }
}

0 个答案:

没有答案