When an interface changes the extended class should be adjusted.
Normally PHP will let you know that by generating a fatal error. It would be nice if you could scan your codebase for these kind of errors. Since it's a fatal error you need something to make sure the script continues.
I created a prototype to show a way how to solve this. It's a prototype just to show the idea. Code needs some improvement ;)
Our fatal error (test.php)
<?php
class test {
public function add(string $message="") {
}
}
class extendTest extends test {
public function add($message) {
}
}
And the scanner
<?php
class interfaceErrorDetector {
public $errors=[];
public function __construct()
{
set_error_handler([$this, 'logError']);
}
public function logError ( $num, $str, $file, $line, $context = null) {
$this->errors[$file] = $str;
}
public function scanFile($file) {
$content = str_replace("<?php", "", file_get_contents($file));
eval($content);
}
public function __destruct()
{
restore_error_handler();
}
}
$handler = new interfaceErrorDetector();
$handler->scanFile("test.php");
print_r($handler->errors);
When an interface changes the extended class should be adjusted.
Normally PHP will let you know that by generating a fatal error. It would be nice if you could scan your codebase for these kind of errors. Since it's a fatal error you need something to make sure the script continues.
I created a prototype to show a way how to solve this. It's a prototype just to show the idea. Code needs some improvement ;)
Our fatal error (test.php)
And the scanner