Earlier quoted context omitted.
I always used and use PHP because it gets the s$$$ done. But truth be told, the hate is deserved. It never was a particularly efficient language, which might not matter that much, but it was riddled with gotchas, warts and horrible solutions to many technical and social problems. Today PHP is faster than many alternatives, many of its warts got fixed, but I cannot brush off the fact that it's still based on a poorly-…
I agree with both statements, it gets shit done but has its rough edges. Its improving though and I doubt there's a perfect programming language out there. At the end of the day what matters are results and how quickly you went from idea to production and PHP is one of the good ones for that matter.
Everything you need (and don't need) to know about PHP's type system
61–67 of 67 posts
Re: Everything you need (and don't need) to know about PHP's type system
#62Minor nits: 1. "they all inherit from stdClass" -- this is simply not true 2. callables should've mentioned anonymous functions 3. a special typed value can't be casted to anything. -- this is not true, NULLs can be casted to anything (it becomes 0, "", array() ) and even resources can be casted to anything with dubious utility value. 4. casting should mention the intval() , strval() , doubleval() functions 5. php do…
Two special notes:
About 1. stdClass, you're right and I don't know why I just took it for granted without even testing. My Bad.
About 3. casting special types, you're right again. I didn't phrase it properly. Casting null to other types won't yield errors and casting resources too. Their values are normally nothing we should rely on, but doesn't mean one "can't" perform such casts.
Thanks a lot for your comments, they are incredibly helpful! Cheers!
Re: Everything you need (and don't need) to know about PHP's type system
#63Earlier quoted context omitted.
Match looks exactly how Rust’s match works and it’s one of my favourite parts of the language. Happy to see it elsewhere too.
It doesn't really pattern match like rust, but it's still very useful
Re: Everything you need (and don't need) to know about PHP's type system
#64Earlier quoted context omitted.
A lot of what Hack introduced to the PHP community has become available in suitably forward-thinking ways to allow for a sensible amount of backwards compatibility and are opt-in. For example, you can set strict typing on a per-file basis. `declare(strict_types=1);` I believe that the performance difference between the two is negligible now too. So it really just comes down to personal preference/platform legacy. But…
the only thing that sucks about strict typing is that there's no way to toggle it globally. so if you want to transition a codebase that's simultaneously actively being developed in other ways, you have to mess around with scripts that append it to the start of all php files/remove it again
I believe this extra step is incredibly important, given most of your dependencies you won't control and forcing strict types to them is not very clever IMO.
Re: Everything you need (and don't need) to know about PHP's type system
#65Completely unrelated but, if the site owners read this: pleas, make the CSS ::selection a different color from the background, please!!
That said: the website is open source, feel free to submit a PR if you find time before I do :D
Re: Everything you need (and don't need) to know about PHP's type system
#66Earlier quoted context omitted.
Eh. If MyPy complains that I'm passing an `Optional[Entity]` into a method where only an `Entity` can go, it's just helped me avoid a runtime error when I try to get `entity.name`. Not sure what the exact PHP equivalent is, but there's all sorts of bugs you can easily introduce if you're not careful with types.
PHP doesn't compile so all errors become runtime errors.
The answers below show a good solution for this issue: use static analysis tools in build time and potentially even as a pre-commit hook.
Re: Everything you need (and don't need) to know about PHP's type system
#67Earlier quoted context omitted.
the only thing that sucks about strict typing is that there's no way to toggle it globally. so if you want to transition a codebase that's simultaneously actively being developed in other ways, you have to mess around with scripts that append it to the start of all php files/remove it again
Nothing that tools like Rector can't help you with. I believe this extra step is incredibly important, given most of your dependencies you won't control and forcing strict types to them is not very clever IMO.