Req #65104 [Opn->Nab]: consider loosing the imposed restriction of typehints

From: Date: Sun, 23 Jun 2013 10:06:04 +0000
Subject: Req #65104 [Opn->Nab]: consider loosing the imposed restriction of typehints
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-179714@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65104&edit=1

 ID:                 65104
 Updated by:         nikic@php.net
 Reported by:        knight at kopernet dot org
 Summary:            consider loosing the imposed restriction of
                     typehints
-Status:             Open
+Status:             Not a bug
 Type:               Feature/Change Request
 Package:            Class/Object related
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Violating type constraints will throw a *recoverable* fatal error. You can register an error handler
to make the code continue executing after it happened.


Previous Comments:
------------------------------------------------------------------------
[2013-06-23 09:59:26] 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.



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65104&edit=1


Thread (2 messages)

« previous php.bugs (#179714) next »