Press "Enter" to skip to content

An Improvement I Made to PHP 5.4 (Compatible-Declaration Error Messages)

A quick side note: today, I finally obtained maintainer rights for Zend. Zend is the most core part of the PHP source code, and also the most sensitive area, whose permissions have always been tightly controlled. But it's also the permission I've wanted ever since I joined the PHP dev group. 🙂
Anyway, back to the point: today I made an improvement to the PHP 5.4 Zend engine — I improved the warning message for incompatible parameters. Specifically:
For the following example:

<?php
class Sub implements ArrayAccess {
    public function offsetSet() {
    }
}
?>

Currently you would always get an error message like:

PHP Fatal error:  Declaration of Sub::offsetSet() must be compatible
with that of ArrayAccess::offsetSet()

The problem here is that the error message doesn't tell us what the correct parameters should look like. Other than looking up the manual (or reading the source), there's no way to find out.
So, after a proposal and discussion within the dev group, I made an improvement today. After the improvement, you'll get the following error message:

Fatal error: Declaration of Sub::offsetSet() must be compatible with
ArrayAccess::offsetSet($offset, $value)

Of course, this also works for user-defined classes, as follows:

<?php
class Foo {
}
Abstract Class Base {
    abstract public function test(Foo $foo, array $bar,
              $option = NULL, $extra = 16777215) ;
}
class Sub extends Base {
    public function test(Foo $foo, array $bar) {
    }
}
?>

which will produce the following error message:

PHP Fatal error:  Declaration of Sub::test() must be compatible with
Base::test(Foo $foo, array $bar, $option = NULL, $extra = 16777215)

reversion: http://svn.php.net/viewvc?view=revision&revision=317206

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.