4 ms·
Symfony and Laravel are really nice. It's still a horrible abomination of a language that invites bugs and requires A LOT of care to not produce buggy code, th
by the_duke 8y ago
Symfony and Laravel are really nice.
It's still a horrible abomination of a language that invites bugs and requires A LOT of care to not produce buggy code, though.
- tomschlick 8y agoIt is getting better though. I'm hoping that 8.0 can introduce some real BC breaks that will clean up the mess the language has created over the years.
- chx 8y agoDoes it? If you declare strict, use strict comparison operators and typehint your arguments and returns, what more care do you need? These are not particularly onerous, the strict declaration is trivially templateable in any editor as it's the first line, you'd write types in any language and getting used to only use === !== and forget == and != is ... easy?
- the_duke 8y agoType declarations definitely help a lot, but: * touching basically any standard library function negates a lot of the benefit * silent coercion still happens everywhere inside a function body Even if strict comparison, you have to spend a lot of code validating the input and it's really easy to forget an edge case.
- vesak 8y agoWhat's the equivalent of === for < and > in PHP?
- chx 8y agoUse < and > for numbers and strcmp for strings. A strict type > would be very weird because besides returning TRUE and FALSE it'd need to throw a TypeError, I guess?
- vesak 8y ago>A strict type > would be very weird because besides returning TRUE and FALSE it'd need to throw a TypeError, I guess? Yes, which would make it behave exactly like probably every language with strong runtime typechecks. Very weird indeed. It's obviously much more preferable that the code sometimes does the wrong thing without warning. And of course with static typing, it would be extremely weird since the code wouldn't even pass the compiler!
- dpcx 8y agoI don't think the snark in this response is super helpful; a simple "Yes, throw a TypeError when the types are incorrect" would have sufficed.
- noir_lord 8y agoThere is an absolutely phenomenal static analyser for PHP called enhanced inspections EA (free version and commercial very) that will flag == when === should be more appropriate (among many other things). For people not using Intellij (or wanting a tool that can be used as part of commit/deploy setup there is phan which is well executed). I've mocked PHP for a long time (been using it for various day jobs for over a decade) but they've made massive strides in the last 2-3 years to the extent where used properly it's approach 'not a bad' language status.
- DCoder 8y ago> what more care do you need? 1. Generic typehints, for one. Typehinting half the methods as returning a generic `array` is not fun. 2. And that's before you even remember that PHP's array is both a vector and a hashmap, so you need to install a PECL extension or a third-party library to get proper Map/Sequence/etc.