How to Override Classes in PHP and Composer

Prerequisites

But First, What’s PSR-4

- app
|
|_ _ _ Model
|
|_ _ User.php
"autoload": {
"psr-4": {
"App\\": "app/",
//....
}
}

Autoloading with Composer

"autoload": {
"psr-4": {
}
}

How to Use This for Overriding Classes

namespace Vendor/Model;
"autoload": {
"psr-4": {
"Vendor\\Model\\": "app/overrides"
}
}

Extra Options

"Vendor\\Model\\": ["app/overrides", "src"]
"autoload": {
"psr-4": {
"": "app/overides/"
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store