cssniper Posted June 12, 2007 Share Posted June 12, 2007 Is there a situation that you will need 2 objects of the same class? Link to comment https://forums.phpfreaks.com/topic/55308-solved-2-objects-of-the-same-class/ Share on other sites More sharing options...
utexas_pjm Posted June 12, 2007 Share Posted June 12, 2007 Absolutely. Consider the trivial example below. <?php class Book { var $author, $title; function Book($author, $title) { $this->author = $author; $this->title = $title; } function getAuthor(){ return $this->author; } function getTitle(){ return $this->title; } } // ... $books = array(); $books[] = new Book("some guy", "some book"); $booker[] = new Book("some other guy", "some other book"); foreach($books as $book){ $book->getTitle() . ' by ' . $book->getAuthor(); . '<br />'; } ?> Best, Patrick Link to comment https://forums.phpfreaks.com/topic/55308-solved-2-objects-of-the-same-class/#findComment-273455 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.