1 | <?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed'); |
||
3 | class History_Model extends CI_Model { |
||
4 | 94 | public function __construct() { |
|
9 | |||
10 | public function updateTitleHistory(int $titleID, $oldChapter, string $newChapter, string $newChapterTimestamp) { |
||
24 | |||
25 | public function getCurrentChapter(int $titleID) : string { |
||
33 | } |
||
34 |
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: