php.net |  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
24 - 2 = ?
Subscribe to this entry?

 
 [2013-06-23 09:59 UTC] knight at kopernet dot org
Description:
------------
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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-23 10:06 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-06-23 10:06 UTC] nikic@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC