Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Are PHP developers functophobic? (nikic.github.com)
4 points by nikic on Aug 10, 2012 | hide | past | favorite | 2 comments


Maybe I'm crazy, but I often include small helper classes in the same file as a larger class, though I guess it's mostly because PHP can't do inner or nested classes, which are useful here and there.

I have to agree, though, that in PHP there's an avoidance of top-level function declarations. The project I work on tends to use wrapper classes with static methods instead of defining top-namespace level functions, and I think it's a little bit better for organization. Possibly I think this because in the 'old' days of PHP (when it was something I wouldn't touch with a 10 foot pole so help me God or Devil) they were everywhere, often redefined needlessly in multiple spots, and inserted at random in spaghetti code files, and so now the more competent PHP devs have a strong aversion to loose functions, even outside of whether they've got a true 'object oriented' thing going on.


Although the trend of always-in-classes and class-per-file didn't necessarily start w/ Zend (was prevalent in many PEAR libs), the fact that they do it makes it fairly standard now.

Having [unfortunately] worked in really large PHP codebases both with an without this level of organization, I can say it is just too painful to maintain unless you can quickly find the source location of a class by knowing its name. Same for functions...globally scoped functions can be difficult to find.

It's probably just as much of a lack of tooling/IDE support as anything, but I welcome the "functophobia".




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

Search: