Created May 23, 2023 09:48
Save unclexo/4c4a81db14222fb3144b6a559302e26d to your computer and use it in GitHub Desktop.
The Liskov Substitution Principle PHP code example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters <?php abstract class Product { private string $filePath; public function __construct(string $filePath) { $this->filePath = $filePath; } public function download() { // Set headers for downloading file header('Content-Type', 'application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($this->filePath) . '"'); // Read the file stream and output it to the response readfile($this->filePath); exit; } } class Audio extends Product {} class Video extends Product {} class Chocolate extends Product {} function download(Product $product): void { $product->download(); } download(new Audio('./dummy.pdf')); // download(new Chocolate('What do I pass???'));You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4