atom feed225 messages in net.php.lists.internalsRe: [PHP-DEV] type hinting
FromSent OnAttachments
43 earlier messages
Sam BarrowJan 4, 2008 10:47 am 
Sam BarrowJan 4, 2008 10:48 am 
Robert CummingsJan 4, 2008 10:49 am 
Sam BarrowJan 4, 2008 10:50 am 
Robert CummingsJan 4, 2008 10:51 am 
Stanislav MalyshevJan 4, 2008 10:52 am 
Stanislav MalyshevJan 4, 2008 10:53 am 
Andi GutmansJan 4, 2008 10:58 am 
Stanislav MalyshevJan 4, 2008 10:59 am 
Stanislav MalyshevJan 4, 2008 11:00 am 
Stanislav MalyshevJan 4, 2008 11:01 am 
Stanislav MalyshevJan 4, 2008 11:04 am 
Sam BarrowJan 4, 2008 11:05 am 
Sam BarrowJan 4, 2008 11:07 am 
Sam BarrowJan 4, 2008 11:08 am 
Sam BarrowJan 4, 2008 11:11 am 
Stefan EsserJan 4, 2008 11:12 am 
Alain WilliamsJan 4, 2008 11:19 am 
Sam BarrowJan 4, 2008 11:19 am 
Stanislav MalyshevJan 4, 2008 11:20 am 
Sam BarrowJan 4, 2008 11:21 am 
Sam BarrowJan 4, 2008 11:22 am 
Stanislav MalyshevJan 4, 2008 11:26 am 
Stanislav MalyshevJan 4, 2008 11:26 am 
Sam BarrowJan 4, 2008 11:27 am 
Stanislav MalyshevJan 4, 2008 11:27 am 
Sam BarrowJan 4, 2008 11:28 am 
Sam BarrowJan 4, 2008 11:29 am 
Sam BarrowJan 4, 2008 11:42 am 
Stanislav MalyshevJan 4, 2008 11:42 am 
Sam BarrowJan 4, 2008 11:44 am 
Stanislav MalyshevJan 4, 2008 11:48 am 
PierreJan 4, 2008 11:50 am 
Robert CummingsJan 4, 2008 11:50 am 
Stanislav MalyshevJan 4, 2008 11:52 am 
Stanislav MalyshevJan 4, 2008 11:53 am 
Robert CummingsJan 4, 2008 11:58 am 
Robert CummingsJan 4, 2008 12:00 pm 
Robert CummingsJan 4, 2008 12:01 pm 
Sam BarrowJan 4, 2008 12:18 pm 
Lukas Kahwe SmithJan 4, 2008 12:18 pm 
Sam BarrowJan 4, 2008 12:20 pm 
Markus FischerJan 4, 2008 1:02 pm 
Andi GutmansJan 4, 2008 1:40 pm 
Brian MoonJan 4, 2008 4:32 pm 
Jani TaskinenJan 4, 2008 4:52 pm 
Hannes MagnussonJan 5, 2008 2:18 am 
Magnus MäättäJan 5, 2008 4:12 am 
Sebastian BergmannJan 5, 2008 4:15 am 
Rasmus LerdorfJan 5, 2008 9:46 am 
Alain WilliamsJan 5, 2008 10:12 am 
Stefan EsserJan 5, 2008 12:48 pm 
Alain WilliamsJan 5, 2008 12:53 pm 
Stefan EsserJan 5, 2008 12:56 pm 
Stefan EsserJan 5, 2008 1:13 pm 
Rasmus LerdorfJan 5, 2008 1:15 pm 
Alain WilliamsJan 5, 2008 2:51 pm 
Vlad BosinceanuJan 5, 2008 3:11 pm 
Daniel BrownJan 5, 2008 3:50 pm 
Mike LivelyJan 5, 2008 3:59 pm 
Markus FischerJan 5, 2008 5:17 pm 
Sam BarrowJan 5, 2008 6:32 pm 
Sam BarrowJan 5, 2008 6:34 pm 
Mike LivelyJan 5, 2008 7:33 pm 
Sebastian BergmannJan 5, 2008 11:34 pm 
Stefan EsserJan 6, 2008 2:05 am 
Alain WilliamsJan 6, 2008 3:28 am 
Stefan EsserJan 6, 2008 4:02 am 
Alain WilliamsJan 6, 2008 4:25 am 
Sven DrielingJan 6, 2008 6:29 am 
Magnus MäättäJan 6, 2008 6:59 am 
Sam BarrowJan 6, 2008 7:54 am 
Sam BarrowJan 6, 2008 7:57 am 
Mike LivelyJan 6, 2008 9:03 am 
Giedrius DJan 6, 2008 9:18 am 
Cristian RodriguezJan 6, 2008 10:40 am 
Cristian RodriguezJan 6, 2008 10:42 am 
Mikko KoppanenJan 6, 2008 12:01 pm 
Markus FischerJan 6, 2008 12:16 pm 
Marcus BoergerJan 6, 2008 12:24 pm 
Stefan PriebschJan 6, 2008 12:37 pm 
PierreJan 6, 2008 12:47 pm 
PierreJan 6, 2008 12:52 pm 
Stefan PriebschJan 6, 2008 12:55 pm 
Markus FischerJan 6, 2008 1:07 pm 
Alain WilliamsJan 6, 2008 1:23 pm 
Markus FischerJan 6, 2008 1:36 pm 
PierreJan 6, 2008 1:40 pm 
Stefan PriebschJan 6, 2008 1:45 pm 
Alain WilliamsJan 6, 2008 1:46 pm 
Marcus BoergerJan 6, 2008 1:47 pm 
PierreJan 6, 2008 2:07 pm 
PierreJan 6, 2008 2:07 pm 
Stefan PriebschJan 6, 2008 2:15 pm 
Stefan EsserJan 6, 2008 2:15 pm 
Alain WilliamsJan 6, 2008 2:22 pm 
PierreJan 6, 2008 2:28 pm 
Stefan PriebschJan 6, 2008 3:00 pm 
PierreJan 6, 2008 4:59 pm 
Martin AlterisioJan 6, 2008 6:58 pm 
82 later messages
Subject:Re: [PHP-DEV] type hinting
From:Rasmus Lerdorf (ras@lerdorf.com)
Date:Jan 5, 2008 9:46:11 am
List:net.php.lists.internals

PHP is first and foremost a Web scripting language. Everything we do and every decision is based on that. For every feature the first question you need to ask yourselves is:

Will this make it easier or harder for the average PHP user to build a web app? And if it makes it harder, is the extra pain worth the benefit?

Given that HTTP is still the dominant web protocol and given that HTTP is not typed, we have to be very careful about introducing stronger typing into PHP, even if it is optional. Passing $_REQUEST['age'] to a function isn't a use-case that can be easily dismissed as it was by someone earlier. This is the primary use case. PHP takes scalar user data which comes across HTTP untyped, does stuff to it, and sends something back.

The argument that adding a type hint will make documentation easier is a scary one for me. If we go and promote the use of runtime type hinting in order for people to use auto-documentation tools, they are likely to sprinkle these type hints everywhere which has the nasty side effect of causing runtime warnings or errors when something returns 1 instead of "1" whereas before this happily worked and worked correctly. And short of fuzzing all your code, you aren't going to catch this case during development.

The robustness principle holds true here:

Be conservative in what you do; be liberal in what you accept from others.

This means that "1" and 1 should be able to travel freely within a PHP script without tripping anything up. And it means there needs to be ways for the code to be conservative in what it does with this data. Today this generally means casting and context-specific filtering.

Robustness and code correctness play against each other to some extent. If you wrote your code in such a way that a function should always be passed 1 and not "1" then it might be nice to know when this isn't the case, which is what type hinting is all about. PHP has always leaned towards robustness, so having your code break in this case goes against the spirit of PHP.

There are ways today to write code that is very strict in what it accepts. It is possible that we can make it a bit easier to write this style of code. But we have to keep this basic principle of PHP in mind and also keep in mind that the type check is only a part (and usually the fastest part) of the conservative data handling strategy. The context-specific filtering, like making sure -1 doesn't turn into 2147483648 in some unsigned backend, still needs to happen with or without type hints.

-Rasmus