Master Php Programming with 50 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.
A class is a blueprint for creating objects. It defines properties (variables) and methods (functions) that the objects will have.class User { public string $name; }
public – accessible from anywhere.
protected – accessible within the class and its subclasses.
private – accessible only within the defining class.
These are known as access modifiers.
Use the new keyword:$user = new User();
This calls the class constructor (__construct) if one is defined.
__construct() is the constructor that runs automatically when an object is created with new.public function __construct(public string $name) {}
It initializes object properties.
Inheritance lets a child class extend a parent class using the extends keyword.class Admin extends User {}
The child inherits all public and protected properties and methods.
An interface defines a contract of methods a class must implement, without providing the method bodies.interface Loggable { public function log(): void; }
A class uses implements to adopt it.
Yes. A class can implement multiple interfaces separated by commas:class Report implements Printable, Exportable { }
This provides a form of multiple inheritance for contracts.
A trait is a mechanism for code reuse in single-inheritance languages. It groups methods that can be included in multiple classes.trait Timestampable { public function now() { return time(); } }
Use the use keyword inside the class body:class Post { use Timestampable; }
The class then gains all methods defined in the trait.
A fatal error occurs unless you resolve the conflict using insteadof or as:use TraitA, TraitB { TraitA::log insteadof TraitB; }
Namespaces organize code and prevent name collisions between classes, functions, and constants.namespace App\Models;
They act like virtual directories for your code.
Use the use statement at the top of the file:use App\Models\User;
You can also alias it: use App\Models\User as AppUser;
Flashcards
Flip to reveal
Focus Mode
Spaced repetition
Multiple Choice
Test your knowledge
Type Answer
Active recall
Learn Mode
Multi-round mastery
Match Game
Memory challenge