News for hackers. Stuff that matters.
Re:A look at modern PHP by koheripbal on Tuesday May 05, 2020 @09:22AM (#23079740)
Coming from Java, the one pet peeve I have is the automatic type conversion. I just find that I never really know what my variables are _really_ holding.

It's one of those foundational issues that I just can't get over.

...but it's my personal problem - I don't hate PHP.

Re:A look at modern PHP by tim_phpdev on Tuesday May 05, 2020 @10:30AM (#23080370)
Work as a PHP dev, in a PHP/JS shop.

In all new work we require static typing on method parameters and defined return types. Of course, if your type is 'array' it could be an array of anything but we also try to avoid that and use collection classes. It honestly feels a lot like Java now, without the compile step.

Re:A look at modern PHP by nucleardog on Tuesday May 05, 2020 @12:56PM (#23082105)
We do similar (strict_types, declare parameter and return types, etc), but don't go as far as the Java-style collection classes except where absolutely necessary.

As a mostly-acceptable alternative, we just type hint as array and document the actual containing types in the phpdoc block and run phan for static analysis to catch any potential screwups.

    /**
     * Method for converting Foos into Bars
     *
     * @param Foo[] $foos
     * @return Bar[]
     */
    function convertFoosToBars(array $foos): array
    {
        // ...
    }
In theory this isn't perfect. In practice we haven't run into any issues yet.
Re:A look at modern PHP by isbjorn16 on Tuesday May 05, 2020 @11:22AM (#23080969)
I do the same in Python with type hinting. It's not actual typing, but at least there are tools that can help call us on our dumbass bullshit.

Edit: and by "our" dumbass bullshit, I mostly mean when we thoughtlessly return type T when we claimed we'd return type U