Project Overview
Part of the Object Oriented Programming section of Coddy's PHP journey — lesson 82 of 91.
Challenge
EasyLet'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 aBookclass that represents a library book. Your book should have three properties:isbn(string),title(string), andauthor(string). Use constructor promotion to keep your code clean. Add a method calledgetInfo()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 aBookinstance with these values and print the result of callinggetInfo().
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
1Fundamentals of OOP
External FilesIntroduction to OOPClasses vs ObjectsThe $this KeywordMethodsPropertiesConstructor (__construct)Destructor (__destruct)Recap - Simple Calculator4Inheritance
Basic InheritanceThe parent:: KeywordMethod OverridingThe final KeywordAbstract ClassesRecap - Employee Hierarchy7Encapsulation
Public, Protected, PrivateAccess Modifiers in DepthGetters and SettersInformation HidingConstructor Promotion (8.0)Recap - Student Records System2Namespaces & Autoloading
Introduction to NamespacesThe use KeywordPSR-4 Autoloading StandardComposer AutoloaderRecap - Organized Project5Interfaces & Contracts
Introduction to InterfacesImplementing InterfacesMultiple Interface ImplementInterface vs Abstract ClassType Hinting with InterfacesRecap - Shape Calculator8Magic Methods
Magic Methods Introduction__toString & __debugInfo__get, __set, __isset, __unset__call & __callStatic__clone & Object Cloning__serialize & __unserializeRecap - Custom Collection11Type System & Error Handling
Type DeclarationsNullable TypesUnion & Intersection TypesException ClassesCustom Exception HierarchyTry, Catch, FinallyRecap - Form Validator14Project: Library Management
Project OverviewBook and User Classes3Class Properties
Instance vs Static PropertiesConstants in ClassesStatic Methods & PropertiesPrivate & Protected PropertiesReadonly Properties (PHP 8.1)Recap - Bank Account Manager6Polymorphism
Method Overriding RevisitedPolymorphism via InterfacesType Hinting & Union TypesLate Static BindingRecap - Payment Processor9Traits
Introduction to TraitsUsing Multiple TraitsTrait Conflict ResolutionAbstract Methods in TraitsTraits vs Inheritance12Design Patterns Part 1
Intro to Design PatternsSingleton PatternFactory PatternObserver PatternStrategy Pattern