Menu
Coddy logo textTech

Project Overview

Part of the Object Oriented Programming section of Coddy's PHP journey — lesson 82 of 91.

challenge icon

Challenge

Easy

Let's kick off the Library Management System project by setting up the foundation — a simple Book class that will serve as the core domain object throughout this chapter.

You'll organize your code across two files:

  • Book.php — Create a Book class that represents a library book. Your book should have three properties: isbn (string), title (string), and author (string). Use constructor promotion to keep your code clean. Add a method called getInfo() that returns a formatted string with the book's details in this format: "[title] by [author] (ISBN: [isbn])"
  • main.php — Include the Book file and bring your class to life. You'll receive three inputs: the ISBN, title, and author of a book. Create a Book instance with these values and print the result of calling getInfo().

This is the first building block of your library system. In the upcoming lessons, you'll expand on this foundation by adding users, borrowing functionality, and administrative features — all working together as a cohesive application.

Try it yourself

<?php

require_once 'Book.php';

// Read input
$isbn = trim(fgets(STDIN));
$title = trim(fgets(STDIN));
$author = trim(fgets(STDIN));

// TODO: Create a Book instance with the input values

// TODO: Print the result of calling getInfo()

?>

All lessons in Object Oriented Programming