1 | <?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed'); |
||
3 | class History_Model extends CI_Model { |
||
4 | public function __construct() { |
||
9 | |||
10 | public function updateTitleHistory(int $titleID, string $newChapter, string $newChapterTimestamp, bool $isNewTitle = FALSE) { |
||
34 | |||
35 | public function getCurrentChapter(int $titleID) : string { |
||
43 | } |
||
44 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: