

More on scalar type hints in PHP trunk
source link: http://schlueters.de/blog/archives/148-More-on-scalar-type-hints-in-PHP-trunk.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

More on scalar type hints in PHP trunk
Some time ago I wrote an article about the implementation of type hints for non-object types for PHP. Meanwhile many things happened and that implementation was replaced by a different one. Readers of my previous post might know that I have doubts about type hints in PHP. People who met me in person and asked me about it know for sure :-)
So what's the status now? - Well type hints, for non-object types, exist and they don't. There is a valid syntax which looks like this:
function foo(int $i) { echo $i; }
What's the consequence of this code? - Well the type hint is simply ignored. This means that
foo("Hello world");
Will run without any error and print Hello world. So there is an syntax looking like another part of the language which throws errors but behaves completely different.
function foo(bar $b) { } foo("bar");' Catchable fatal error: Argument 1 passed to foo() must be an instance of bar, string given [...]
The int hint is just one of them, there are a few more:
- bool, boolean
- string, binary
- scalar
- numeric
- int, integer, long
- real, double, float
- resource
- object
Recommend
-
54
Contributor
-
66
JVM Anatomy Quark #18 JVM Anatomy Quark #18: Scalar Replacement About, Disclaimers, Contacts
-
59
Recently, I read an interesting article from Andrew Carter entitled Make PHP Great Again [chea...
-
30
What’s the most common type your Perl 6 code uses? I’ll bet you that in most programs you write, it’ll be Scalar . That might come as a surprise, because you pretty much never write Scalar
-
44
PHP 8 is just around the corner. It's time for PHP to have scalar objects. Together we can do this. Join the movement!
-
6
Features in PHP trunkJohannes Schlüter This post is archived and probably outdated. Features in PHP trunk: Array dereferencing 2010-07-31 13:11:39 I was writing about...
-
11
No more extension for sqlite version 2Johannes Schlüter This post is archived and probably outdated. Changes in PHP trunk: No more extension for sqlite version 2 2010-11-22 07:48:00
-
10
Scalar type hints in PHP trunk 2010-08-07 23:00:00 So in my blog series I try to cover all additions to PHP trunk so I have to mention scalar type hints....
-
9
Upload Progress in PHP trunk 2010-12-03 19:31:40 File uploads via HTTP are an annoyance. Web Browser know quite a lot but still the give little feedback to the users. Some a bit more, most close to no feedback. Now over...
-
4
scalar type-casting Since PHP 7.0, I've started using scalar type-hints a lot, and it got me thinking about scalar type-casting. After poking through existing RFC's, it turns out, I was goi...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK