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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: knight at kopernet dot org
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Sat Dec 21 18:01:29 2024 UTC