Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>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.



The 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.


Function 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(){}


Its not true at all.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: