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

I've worked with PHP since 5.4, and to me the language has not been the obstacle, it has been my own skill-level that has held me back, and still is - I lack very much the core architectural skills in getting forward as a developer, among many other things.

I've seen some codebases using an even older version, and I think I can understand where people are coming from with their angst towards the language - but I think we should look at ourselves before we jump to the bandvagon of just hating something blindly - I remember being part of the "Apple sucks" group for no other reason than hype, and now I've used one for years as a work machine.



I got back into web development in the last year or so. Previously I did mostly Python/Django and then 5 years of something unrelated to dev. Now I'm working in a fairly typical PHP/Wordpress mixed joint, and now I understand why PHP has the bad rep - because it allows/tolerates/even encourages bad practices (and beyond the usual "shoot yourself in the leg" we can see in other popular/common languages). And I guess that is one of the reasons why a lot of libraries/plugins/php code out there is simply bad. For example: Seeing heavy mixing of PHP code and HTML output in 2020 is a horrible sight for me (and it's waaay to common in what I saw).

Of course you can write good code in modern PHP, but you can write really bad stuff too - more (at least imho) than in other popular languages. And then the whole ecosystem "drags you down" and gives PHP a bad rep -> but I don't think it's totally undeserved.

On a similar note, this actually compelled me to try Rust/something similar instead of just going straight back to Python (which I still love tbh).


The thing I hate about php is the inconsistency and unpredictability for new-to-php developers.

camelCase? snake_case? nocase? Who knows what the global function will be.

And who knows what order the arguments should go in. Sometimes the array is first, sometimes not (in array iterating functions like map).

The thing that got my goat the most however was that referencing an undefined variable merely caused a warning, but referencing an undefined key in an array borked it.

And what's with arrays and maps being the same thing?!


FYI when you start a PHP project you need to change your dev machine php.ini to be super strict, so all warrnings should just error out.

The inconsistency seems to have it's logic and at that time was consistent and made sense, you need a good IDE to help with this. Using PHPStorm and then using PHPDoc to define your functions parameters and return type is a joy, the IDE will catch your type mistakes, show you where you missed to catch an exception and it will code complete stuff.


It never made sense. The original hash bucketing mechanism for the function lookup in PHP was the length of the name of the function, so each new function was named a specific length to ensure the function list was evenly distributed across the hash table.


Can you link or be more clear? I assumed you are talking about the array and string related functions that are not consistent in argument order.


The parent comment is referring to https://news-web.php.net/php.internals/70691 (found via https://news.ycombinator.com/item?id=6919216). Quoting from that link:

  Well, there were other factors in play there. htmlspecialchars was a
  very early function. Back when PHP had less than 100 functions and the
  function hashing mechanism was strlen(). In order to get a nice hash
  distribution of function names across the various function name lengths
  names were picked specifically to make them fit into a specific length
  bucket. This was circa late 1994 when PHP was a tool just for my own
  personal use and I wasn't too worried about not being able to remember
  the few function names.


Thanks, I did not know that bit of history.


Thanks for the tips! I suspect PHPStorm/Doc may be the only one that flies for the legacy codebase I sometimes get involved with - turning warnings into errors would be suicidal...


You don't turn warnings into error on production but it will help to have them enabled on your local machine, otherwise errors are ignored and you would waste your time debugging weird issues. You can do this per file too using the "ini_set" https://www.php.net/manual/en/function.ini-set.php


This has been my experience too. Ten+ years ago I had already concluded that the biggest problem PHP has is the community. Googling for "php mysql" you still end up on w3schools and the like where SQL injection is still not emphasized. Everyone was making their own frameworks and software from scratch. My last foray into PHP, and my realization that it's not actually all bad, was working in Zend Framework (iirc this was also when Ruby on Rails was fairly new and gaining popularity fast).

I haven't touched it (beyond very basic edits on my website, wordpress etc) for over a decade, but recently I inherited an older codebase at my new job. The existing codebase is an absolute mess, worse than the shit posted in those tutorials I mentioned.

But as part of the job (beyond rebuilding the application), I also had to add a big new feature to the application, a REST API. Keep in mind that due to constraints on the systems we install on, it had to be made in PHP 5.2 or 5.3 - one difference being that the older version doesn't even support an array creation shorthand (`$var = []`).

I could keep interactions with the existing codebase to a minimum. The rest was... actually surprisingly all right, thanks to me knowing what a REST API is and how to structure an application properly.

I did have to basically write my own framework (sigh) because pretty much nothing is still available that works on pre-array-shorthand-versions of PHP, but it was fairly minimal; an off-the-shelf router and URL matcher (can't be arsed with writing that myself), middleware for authentication, and a simple class structure to encapsulate different output formats (json, csv, streaming plain text).

Granted, this old version of PHP is seriously rough around the edges, and at the time it already represented great advancements in the language. I mean before 5.4 the language didn't even have a function to set the HTTP response code (you had to write the header manually).


Thanks, that made me smile. I got out of php a few years ago and 5.x is still the new kid on the block for me, with all this crazy enhancements! :-D

Though I also totally forgot things like array creation syntax and wonder how I could have ever lived without stuff like that shorthand.


Good, that you can confirm your skill level, so maybe PHP suites you very well.

For me, having no standard HashMap and having to set strict mode params in functions - is an instant no go. There is no lack of better options.


> Good, that you can confirm your skill level, so maybe PHP suites you very well.

Could you elaborate on this one, I am not exactly sure what you mean by it.




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

Search: