Consider the following two files:
ParentClass.php
<?php
abstract class ParentClass
{
abstract public function foo(array $arg1, array $arg2);
}
ChildClass.php
<?php
require_once "ParentClass.php";
class ChildClass extends ParentClass
{
public function foo(array $arg1)
{
print_r($arg1);
}
}
Now, let's try linting these files:
$ php -l ParentClass.php
No syntax errors detected in ParentClass.php
$ php -l ChildClass.php
No syntax errors detected in ChildClass.php
Great, no syntax errors!
But wait! There's a problem:
$ php ChildClass.php
PHP Fatal error: Declaration of ChildClass::foo(array $arg1) must be compatible
with ParentClass::foo(array $arg1, array $arg2) in
/home/mkasberg/php_syntax_check/ChildClass.php on line 5
So, why didn't php -l
catch it? That's an error that could be caught at "compile time" (although php is not a compiled language). Seems like php -l
could notice that the declarations are not compatible. Is there a way to run php -l
such that it will catch this error? Is there another tool that will catch the error?