Hi internals,
I carefully read all 3 proposed RFCs related to scalar type hints.
As an end user and enthusiast of the language, I want PHP to always
improve. STH is the major inclusion for PHP 7 and no matter how many
people say about phpng performance, STH is the one that will impact mostly
everyone on a day by day basis.
Now I also understand the rush of getting this feature in PHP considering
the voted and approved deadline for feature freeze of PHP 7. However, we're
not in a mission critical, losing millions or facing a world collapse if it
takes an extra day or two to figure it out what people want, specially such
an important feature. That said, I consider the feature freeze date a soft
deadline than a hard one, and again, keeping in mind we could be
potentially delaying the freeze due to the importance of what we're
deciding.
Back to the subject. I am a a strict camper, but I understand the nature of
PHP and its loose type.
Considering the 3 RFCs, and also counting the number of WTFs each one adds,
I hereby describe my choice.
By considering PHP's nature, having a dual mode is a WTF. I can see myself
asking multiple times a day "is this file strict or not?" to trace
potential bugs or type juggling. I do want strict, but I don't think it's
the right time for PHP to make this move. Userland would have strictness,
but all internal functions are a weird WTF type juggling mode. I originally
switched my vote many times in the v3 of the RFC, mainly because PHP
developers are the ones that would suffer by these configurability on a
daily basis. I ended up with a YES vote because when considering STH or
nothing at all, I prefer to have some.
Coercive STH already added a WTH by not being inline with ZPP. It also have
a timely migration path to turn them in sync, which would bring more
breakage, more refactoring and more headache.
Basic STH is the only one inline with ZPP, and the mostly natural for every
PHP developer. They understand how internal PHP functions work and they
know what to do. It also does not have the duality mode as v5 RFC.
Therefore, this is where I'd place my vote.
However, I do think that ZPP needs to migrate as Coercive STH partially
defined to a stricter conversion scenario. That is what Basic STH should
follow, but at the same time pace, not creating a discrepancy now and a WTF
to userland. Ideally, Basic STH should also reuse ZPP support, meaning that
any updates to ZPP would also benefit the STH.
That said, I'll place my vote as YES in Basic STH and vote NO for the other
ones.
Regards,
--
Guilherme Blanco
MSN: guilhermeblanco@hotmail.com
GTalk: guilhermeblanco
Toronto - ON/Canada
By considering PHP's nature, having a dual mode is a WTF. I can see myself
asking multiple times a day "is this file strict or not?" to trace
potential bugs or type juggling. I do want strict, but I don't think it's
the right time for PHP to make this move. Userland would have strictness,
but all internal functions are a weird WTF type juggling mode. I originally
switched my vote many times in the v3 of the RFC, mainly because PHP
developers are the ones that would suffer by these configurability on a
daily basis. I ended up with a YES vote because when considering STH or
nothing at all, I prefer to have some.
The bigger WTF is perhaps that moving forward one has no idea just what
a third party library is using internally. A case has been made that
this does not matter since calling that library from a non-strict site
will simply work as now, but in that case the library is not designed to
handle non-strict input. It assumes that the strict check happens, where
a well designed 'weak' library will be handling the edge cases properly.
It not simply a matter of "is this file strict or not?" but rather "what
happens when I pass the wrong data?".
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
By considering PHP's nature, having a dual mode is a WTF. I can see myself
asking multiple times a day "is this file strict or not?" to trace
potential bugs or type juggling. I do want strict, but I don't think it's
the right time for PHP to make this move. Userland would have strictness,
but all internal functions are a weird WTF type juggling mode. I originally
switched my vote many times in the v3 of the RFC, mainly because PHP
developers are the ones that would suffer by these configurability on a
daily basis. I ended up with a YES vote because when considering STH or
nothing at all, I prefer to have some.The bigger WTF is perhaps that moving forward one has no idea just what
a third party library is using internally. A case has been made that
this does not matter since calling that library from a non-strict site
will simply work as now, but in that case the library is not designed to
handle non-strict input. It assumes that the strict check happens, where
a well designed 'weak' library will be handling the edge cases properly.
It not simply a matter of "is this file strict or not?" but rather "what
happens when I pass the wrong data?".
If I've understood the RFC's correctly, your point is moot. With any scalar type hints, a library will not be able to tell how it is being called. All it knows is that it has received an int, string, float, or boolean where it has asked for one. A library written in weak or strict mode will have no bearing on its public API. This is the case with all of the STH RFCs.
So no, a weak mode library is not better off. It is actually worse off because it has more edge cases where things could go wrong (internally), while a strict library will not function at all until the edge cases are actually taken care of.
As far as being a user of the library itself, the strictness or weakness of the library code is irrelevant. You can use a weak library in strict mode, and the library would never know or care.
if you decide to make all your own code strict, you're not changing the behavior of the library. If you make all your own code weak, you're not changing the behavior of the library. Even if you strips out all the declare strict statements, it will not change the behavior of the library (except in the case where the code was broken and wasn't even working previously!).
I think the best way to explain the dual mode RFC is to think of it like this:
Imagine PHP threw a COERCIBLE_TYPE_MISMATCH notice whenever you pass the wrong type to a function. In weak mode, the type gets coerced, the notice is ignored, and we truck along as if nothing happened. Strict mode is basically where you've set up a custom, per-file error handler where COERCIBLE_TYPE_MISMATCH notices are turned into fatal errors. It is your code that decides which error handler to use.
Cheers,
David
By considering PHP's nature, having a dual mode is a WTF. I can see myself
asking multiple times a day "is this file strict or not?" to trace
potential bugs or type juggling. I do want strict, but I don't think it's
the right time for PHP to make this move. Userland would have strictness,
but all internal functions are a weird WTF type juggling mode. I originally
switched my vote many times in the v3 of the RFC, mainly because PHP
developers are the ones that would suffer by these configurability on a
daily basis. I ended up with a YES vote because when considering STH or
nothing at all, I prefer to have some.The bigger WTF is perhaps that moving forward one has no idea just what
a third party library is using internally. A case has been made that
this does not matter since calling that library from a non-strict site
will simply work as now, but in that case the library is not designed to
handle non-strict input. It assumes that the strict check happens, where
a well designed 'weak' library will be handling the edge cases properly.
It not simply a matter of "is this file strict or not?" but rather "what
happens when I pass the wrong data?".
If I've understood the RFC's correctly, your point is moot. With any scalar type hints, a library will not be able to tell how it is being called. All it knows is that it has received an int, string, float, or boolean where it has asked for one. A library written in weak or strict mode will have no bearing on its public API. This is the case with all of the STH RFCs.So no, a weak mode library is not better off. It is actually worse off because it has more edge cases where things could go wrong (internally), while a strict library will not function at all until the edge cases are actually taken care of.
As far as being a user of the library itself, the strictness or weakness of the library code is irrelevant. You can use a weak library in strict mode, and the library would never know or care.
if you decide to make all your own code strict, you're not changing the behavior of the library. If you make all your own code weak, you're not changing the behavior of the library. Even if you strips out all the declare strict statements, it will not change the behavior of the library (except in the case where the code was broken and wasn't even working previously!).
I think the best way to explain the dual mode RFC is to think of it like this:
Imagine PHP threw a COERCIBLE_TYPE_MISMATCH notice whenever you pass the wrong type to a function. In weak mode, the type gets coerced, the notice is ignored, and we truck along as if nothing happened. Strict mode is basically where you've set up a custom, per-file error handler where COERCIBLE_TYPE_MISMATCH notices are turned into fatal errors. It is your code that decides which error handler to use.
Thank you for that David ...
It makes sense of a number of points.
I think that what I really need is a simple crib sheet of 'just' weak
typing in this RFC and if that conflicts with my own current program
flow. I simply don't subscribe to the implication that type hinting is
essential to make PHP better. I just prefer in-line error handling to
exception handlers.
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk