1 | <?php |
||
21 | class Config_Util extends \eoxia\Singleton_Util { |
||
22 | /** |
||
23 | * Un tableau contenant toutes les configurations des fichies config.json |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | public static $init = array(); |
||
28 | |||
29 | /** |
||
30 | * Le constructeur obligatoirement pour utiliser la classe \eoxia\Singleton_Util |
||
31 | * |
||
32 | * @return void nothing |
||
33 | */ |
||
34 | protected function construct() {} |
||
35 | |||
36 | /** |
||
37 | * Initialise les fichiers de configuration |
||
38 | * |
||
39 | * @param string $path_to_config_file Le chemin vers le fichier config.json. |
||
40 | * |
||
41 | * @return mixed WP_Error si il ne trouve pas le fichier config du module |
||
42 | */ |
||
43 | public function init_config( $path_to_config_file, $plugin_slug = '' ) { |
||
66 | } |
||
67 | } // End if(). |
||
68 |
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: