I searched many solutions here on Stackflow but i dont get it fixed. Its simple i have a class Library and i want to store Books object there and display them. My code is simple but i dont get it. I am getting this ERROR: Undefined variable: books
class Library{
var $books = array();
function addBook($bok){
$books[] = $bok;
}
function displayBooks(){
foreach($books as $b){
$b->display();
}
}
}
class Book{
var $title;
function __construct($name){
$this->title = $name;
}
function display(){
echo $this->title;
}
}
$lib = new Library();
$lib->addBook(new Book("Test Title"));
$lib->displayBooks();
$this->booksand not$booksvarnot recommended since release of PHP 5.0 (that was in 2006 or so) ... you might need to get a newer tutorial/book.