And we also used all other best practices such as PSR code formatting standards, linters, code reviews, etc.
But I work on a small team.
We use PHPUnit for unit testing, but this is not related to types.
> bugs that a typed language would prevent
This sounds like you think PHP isn't typed. It is, and with 8.1 (and even more so 8.2) the type system isn't exactly Haskell (ha) but gets much stronger than it historically has been for PHP.
You enable a feature called strict_types which enforces these rules.
Then you have a layer of even more powerful type checking and analysis which, though not enforced at the runtime level, is picked up and validated against by your IDE's real-time (or async external) static analysis tools. This is partially in phpDoc and there are various ways to do it.
Then, besides static analysis with popular tools like PHPStan or Psalm, there are nice inspection tools like EAInspections, Sonar, etc that check for hundreds of possible errors, code smells, style issues, etc.
Large, professional PHP codebases are not a big wild west of implicit coerced dynamic types. For my own projects, I consider any avoidable reliance on PHP's dynamic typing a bug, i.e. casting null to bool in conditionals.
Fully embracing PHPStorm, strict_types and EAInspections completely changed me as a developer. I hated them at first, just getting in the way and annoying me… But now several years later and I fully credit them for revitalising my career and giving me a newfound love for coding.
When you find parts that you can't easily type (open file handlers for example), you can create wrappers that encapsulate the handlers.
Also, use phpstan/Phan or other static analyzers like others mentioned.
It’s always appropriate. A good IDE should highlight == as a warning.
My code quality and programming abilities got significantly better since forcing strict types and comparisons on myself. I can’t imagine writing PHP any other way now.
In this case === will always return false since it checks if the two instances are the same object.
Set up a linting rule that every project PHP file (with some exceptions, like templating files) needs to have the `declare(strict_types=1);` directive. Then you can also have PHPCS fix it or just generally have linting checks on PRs.
For large legacy apps you can still add exceptions.
I know you mean: "when i hit compile i dont see the errors directly" but that can be achieved by activated the strict type setting and your screen will turn red too =)
I really think that, from all the frameworks i have used, symfony actually has the most decent debugging system. it comes with tracing logging and live debugging. so pretty much everything you would get out of any other language.
With xdebug and editors like phpstorm you are also able to pretty much mimic working with PHP as you would with C#. I believe there are working plugins for Visual Studio too.
Just as an excourse, I have also worked with projects that compiled php to other languages too on the fly.
Stack Overflow makes a lot more sense when you think of it as Wikipedia run by mathematicians rather than a forum. If your question is ambiguous or open for discussion, it's probably not a good fit for Stack Overflow.
I don't spend much time on there anymore but now you know
I have found that working in a team with php has made it, sometimes, difficult to catch bugs that a typed language would prevent at compile time.
How do larger teams work with php and frameworks like Laravel and prevent errors that are related to type-checking?