← PHP learning path
PHP · Module 8 of 10

Object-oriented PHP

Use classes, interfaces and namespaces.

📖 Key ideas

  1. class User { public function __construct(private string $name) {} }
  2. Interfaces, abstract classes and traits.
  3. Namespaces organise code: namespace App\Models;
  4. Composer manages packages and autoloading.
  5. Follow PSR standards (PSR-4, PSR-12).
💡 Real-life example: Namespaces are city areas: two "Main Street" names don't clash when they're in different cities.
Constructor promotionDeclare properties in constructor
TraitReusable method set
NamespaceGroups related code
ComposerPHP package manager