dsxjot8620
2017-07-24 16:07
浏览 34
已采纳

如何在PHP OOP中仅使用过滤内容创建对象

I have created a class with constructor in php which filter xml file. But the object created take all xml data. How can I avoid that?

Thank you for your help!

My code:

class  Property {
    public $xmlClass;
    public $elemClass = '';
    public $result_array = [];
    public $data = '';

    public function __construct($xml,$elem) {
        $this->xmlClass=$xml;
        $this->elemClass=$elem;

        foreach($xml->list->movie as $value) {
            $data = $value->$elem;
            $result_array[] = $data;
        }

        print_r($result_array);                   //here everything is ok
    }
}

$result_title = new Property('title');
print_r($result_title);    //here object takes all data, not only filtered
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题