On Thu, May 27, 2010 at 5:47 PM, Lukas Kahwe Smith <m...@pooteeweet.org>wrote:

>
> well most people do not use that since its just as tedious to use as having
> to cast your results. of course if we did have strict typing it would
> probably become more widely used, not that having to add those lines of code
> are something i would like to see in my code (the speed gains are
> microoptimizations for most use cases of PHP).
>
> regards,
> Lukas Kahwe Smith
> m...@pooteeweet.org
>
>
>
Hi again,

A few other thoughts from a user.

I have been trying to think of use cases where, keeping in mind that we are
talking about a dynamic scripting language, it would be useful to have
strict type checking for function parameters. So far I have found and read
none. I completely agree with Zeev, Lukas, Stas and the others.

Granted, PHP already has inconsistencies on this level. Several core
functions work only if their parameters are of the correct type. In my
opinion, that has always been a dark corner of the language. Why am I told
by the documentation that PHP is a dynamic language if these functions can't
treat the string "3" as an integer, which it so obviously is? Or the
reverse? I can live with a few exceptions, but introducing a new
language-level syntax that would force me to cast my variables in seemingly
random places (for someone reading my code), I just don't see the point.

Yes, PHP already has some strict type checking with arrays and objects. I
think these two cases are very useful, but that would not be the case for
scalar values. I almost never use the same functions on arrays as I do on
scalars or objects. If my API won't be able to call specific methods of a
parameter because it is not the right class, or not an object at all, I want
to know about it as soon as possible: that's a programming error, not a
user-supplied value (these are always scalars). I can see no such use case
with scalars because, as Zeev said, most of the time they are
interchangeable.

Calling a function with a scalar value (whatever the source) instead of an
object or an array is a programming error because PHP has no way to auto
convert a scalar into an array or into an object. However, sending a scalar
(maybe typed "string") to a scalar type-checked (maybe expecting "integer")
PHP parameter is usually not a programming error, it is a legitimate and
very common use-case. If the data is wrong, the called function will
validate it anyway.

Another aspect is that there are means to trust (some of) the data. I can
configure my database to send data to PHP* via *a TLS connection, so that I
know for sure that the data I am feeding to my app comes from a schema I
know very well, and therefore the data is the right type even if it is
represented as strings. This has always been a strong point for PHP. The
type of the values is an implementation detail I, as a PHP developer, want
to have to deal with as little as possible. Dynamic typing is one of the
main arguments that have seduced in the first place. I myself know something
about zvals because I read this list from time to time, but not in detail
because my interest in them is purely academic. As a user, I just don't care
about zvals.

As it has been said several times before, strict typing is *not* optional,
it *will* be forced on me. And as a regular PHP user, I don't want that to
happen too often. If strict typing for scalars in a new language-level
syntax is introduced, I will eventually be forced to use it in all my code
for consistency, or just to be sure my code won't break after I upgrade my
libs. I already have to cast XML nodes to one of the scalar types, but as a
user I can understand the need to explicitly convert complex types when I
use them as scalars (and *vice versa*). I wouldn't, however, understand the
need to cast scalars into other scalars. PHP handles that fairly well most
of the time, and when an edge case arises I can do a cast. I just don't want
to have to explicitly cast each variable each time I am using them to call a
function, as strict type checking would have me do. My code would be
unreadable, and very unlike PHP code as I know it.

If I wanted a strictly typed language, I wouldn't have chosen PHP. On the
contrary, I thank PHP for its type juggling and conversion rules.

Thanks for reading me,
Best regards,

Reply via email to