IllegalArgumentException for Type hints

  Status: implemented,  Thu Feb 1 18:04:40 CET 2007
  • Created: 2006-12-17 20:18:10+0100
  • Categories: <core>
  • Author: friebe

Scope of Change

Methods declared with type hints will throw an IllegalArgumentException when type mismatches occur.


Rationale

Fatal error prevention.

Functionality



What happens currently

$ php5 -r 'class Test { static function x(Object $o) { }} Test::x();'

Fatal error: Argument 1 passed to Test::x() must be an object of class 
Object, called in Command line code on line 1 and defined in Command 
line code on line 1

How to fix it

Prepending this:

  set_error_handler(
create_function
('$c, $m', 'throw new Exception($m);'),
E_RECOVERABLE_ERROR
);

... to the above code will yield in an uncaught exception instead of a fatal error.

Security considerations

n/a

Speed impact

n/a

Dependencies

- This RFC will bump the version number to 5.3.0

Related documents

- http://xp-framework.net/rfc/contrib/rfc0100.diff Patch for lang.base.php

- http://www.derickrethans.nl/erecoverableerror.php E_RECOVERABLE_ERROR announce

Comments



<EOF>


Table of contents