<?php
namespace Shop\Models;
use Shop\Models\Address as AddressClass;
/** @var Address parent */
class_alias(defined('AddressClass') ? AddressClass : Address::class, 'ThingPink\Shop\Models\AddressClass');
/**
* Class BillingAddress
*
* @package Shop\Models
*/
class BillingAddress extends AddressClass
{
...
}
- Can simply extend the class that we need to overwrite some function and point the alias to it (do not need rewrite the entire class)
- Every file with this strategy lose IDE type hints from parent and eventually every type hints for classes with this strategy
- Need to add this alias code to EVERY class in order to make em "replaceable"
composer.json
...
"autoload": {
"psr-4": {
"Shop\\Models\\": "./extended"
}
},
...
Where inside the ./extended
folder exists the class(es) that you want to reimplement.
- Do not need to change a thing in vendor classes in order to adapt extensibility
- IDE automatically just read the "overwritten" version, meaning that we get out of the box all the IDE hints
- Need to rewrite entire classes (instead just extend em and overwrite the desired changes)