|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65104 consider loosing the imposed restriction of typehints
Submitted: 2013-06-23 09:59 UTC Modified: 2013-06-23 10:06 UTC
From: knight at kopernet dot org Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2013-06-23 09:59 UTC] knight at kopernet dot org
Typehints are means to introduce typesafety into PHP code which should futher improve the code reliability and robustness.

Considering that PHP language is dynamic in nature it's difficult to fulfill the promise completely as there's no compilation stage that integrates calling code with the modules that might make extensive usage of the hint.

Failing to satisfy the expectations of typehints generates a fatal error though.
Unfortunately it can only be detected at runtime and that can be very late when the misfortunate code path is executed - at edge case never.

The most real usage of the typehints are made by advanced IDE like Eclipse PDT or PhpStorm which use it to provide advanced intellisense like code completition and near compile quality static code analisis. In those development environments similar effect can be achieved by adding a proper phpdoc annotation block before the method signature. It's much more verbose though and naturally a typehint is a very succinct replacement and it's where I see the most value of the typehints.

Given the above please consider replacing the current behavior of throwing a fatal error in case of a mismatch by just emitting a warning.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-23 10:06 UTC]
-Status: Open +Status: Not a bug
 [2013-06-23 10:06 UTC]
Violating type constraints will throw a *recoverable* fatal error. You can register an error handler to make the code continue executing after it happened.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 11 20:01:29 2023 UTC