Since I can't see the forest from the trees here, care to provide an example or two?
I've had cases where I want to only allow certain values (most often int) into certain functions (usually __construct, when looking at a primary key in a database), but in these cases I prefer to cast values. (int)$foo hasn't failed me yet, and I've internalized it as much
as I've internalized running application output through htmlentities.
I can see this being extremely useful if you plan on using PHP as a general purpose language, but I never have. I'd rather jump to Java/C++/Rust if I had to do numeric calculations (things like images, real time calculations, etc.)
Let's say the constructor you mentioned is for an ORM. Let's also say you're using a database library or PHP extension that you're not 100% familiar with, or maybe it just has a bug in a new version that you just updated to.
You pull out a particular row from this library/extension, and it contains an empty string (or even null) as the value for the primary key field.
Using typecasting, you'd get a value of 0, which is wrong. It would fail silently, and you'd only discover the error when you realize you're working on a row with no data. You'd even be able to update the row silently, because "UPDATE whatever SET x = y WHERE id = 0" is valid SQL!
With primitive type hints, you'd know immediately that you're getting an empty value from your DB, and you could go straight to fixing that instead.
In the past, people have had to write a bunch of unit tests to avoid all these issues. With primitive type hints, you could just type the word "int" and be done with it.
All that said, I still say all the people that are excited about this are much better off switching to a strictly-typed language, because my example above is just the tip of the iceberg when it comes to juggling types.
I take your point that this is nice syntactic sugar, but I don't like your example. You wouldn't typecast in this situation. You would check the value with is_numeric() or similar.
I've had cases where I want to only allow certain values (most often int) into certain functions (usually __construct, when looking at a primary key in a database), but in these cases I prefer to cast values. (int)$foo hasn't failed me yet, and I've internalized it as much as I've internalized running application output through htmlentities.
I can see this being extremely useful if you plan on using PHP as a general purpose language, but I never have. I'd rather jump to Java/C++/Rust if I had to do numeric calculations (things like images, real time calculations, etc.)