9 ms·
>functions are global so you now need to name them uniquely to avoid collisions I hear this here, and elsewhere I hear that PHP has evolved into a decent langu
by brlewis 3y ago
>functions are global so you now need to name them uniquely to avoid collisions
I hear this here, and elsewhere I hear that PHP has evolved into a decent language. Both can't be true.
- afiori 3y agoFunction names are scoped to the current namespace. This means that for local closures it is usually better to define functions as variables $closure = function(){}; instead of function closure(){}
- moritzwarhier 3y agoThe discussion thread here may underrepresent OOP PHP. Large software in PHP usually uses namespaces instead of declaring functions at the top-level scope. And most projects except for legacy ones lean towards objects and classes over plain functions. Namespaces allow non-global functions without a wrapping class already, IIRC. Looking up though, there seem to be special cases (legacy behavior, making everything at the top level global) when using namespaced files with include() statemtents, if I read the docs correctly. Dumping pure functions as static members into wrapper classes was not uncommon when I used PHP. But primarily, a lot of code was heavy on dependency injection and inversion of control, Symfony being the leader of this coding style maybe. TFA also seems to be about class-oriented programming, but not the heavy design-pattern style mentioned above. The linked TUI CLI parser looks like a nice and lean PHP OOP example.
- archerx 3y agoIts not true at all.