Hi!

All right, your method accepts an array of objects, instances of Foo. How do
you enforce this contract?

You are trying to re-invent generics/parametrized types and bolt it onto
PHP. I still don't think it is a good idea - PHP is not a statically
typed language. Just check you array elements if you need.

You're 10 years too late to argue the merits of typehints in PHP.

I am not proposing the introduction of typehints. I'm just saying "we have the option to use them in arguments, let's have the options inline too." This way we can validate expressions and structures we can't today, in a minimal, readable, consistent, easy to maintain way.

By "peppering" here you mean one if. Yes, this is my proposal - if you
need to do a check - do a check.

Yes, exactly: one if. For your entire codebase that has one single assignment in it.

Or one foreach. Pick one or the other, but not both, otherwise they become two ifs, and that invalidated your argument.

The same applies to typehints, so make up your mind.

No it does not. But this is exactly why I think one of the problems with
strict typing in arguments is - because people take it and starting to
use it as a legitimation of turning PHP into weird hybrid of dynamically
typed language with random islands of static typing popping in random
places. I still do not think it is a good idea.

Saying "weird hybrid random islands popping random" doesn't make simple type validation hints any more awkward than they were yesterday before I posted this thread, Stas.

Stan

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to