dsyq40772 2011-02-24 21:07
浏览 57
已采纳

PHP:在OOP中追加对象?

I've transitioned my coding step by step into OOP, which feels great. What I haven't got a hold of yet, is when It's time to use an object and when to use the conventional arrays.

Let's say that I would have the following code. Here we create an array containing Persons - receivers of emails. It's really cute, but it feels kind of smelly to jump back and forwards between arrays and objects.

Are my concerns legitimate or is this good practice?

public function receiver($email, $name = FALSE) {

    $person = new Person();
    $person->email = $email;
    $person->name = $name;

    $this->receiver[] = $person;
}
  • 写回答

4条回答 默认 最新

  • dongxi7722 2011-02-24 21:08
    关注

    That's absolutely fine, OOP doesn't preclude using arrays where appropriate.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?