
Why people hate PHP, a book from hell - Iqth
http://blog.neattutorials.com/why-people-hate-php-a-book-from-hell/
======
aikah
TLDR; op blames awfull books that spread bad practices and then made PHP code
ugly and insecure.

I personally don't care about PHP.

Now the PHP community is kinda funny. Basically there are the people that use
PHP as poor man's java, that feel the need to write 50 design patterns per
file, who hates the other part of the community, the one that couldn't care
less about "software engineering best practices".

So it's not much that people hate PHP, more like PHP developpers hate other
PHP developers because they feel the need to be labelled as "good" PHP
developpers, unlike the "bad" ones.

~~~
EugeneOZ
If you can say "write 50 design patterns per file" then you don't know what
design patterns are.

~~~
chupy
I think that was exaggeration to make a point and also for the sake of comedy.

------
erikb
I think PHPs big strength is the other point mentioned in the post: It enabled
lots of people who are not really programmers to do some programming. Some of
them developed into serious developers, some of them didn't. Being able to
produce something slightly meaningful even without any skill is a big
accomplishment, but it also means loads of erros, over estimated skill levels,
security holes, unreadable code etc. The reason this doesn't happen to Haskel
is that you become a computer scientist first and then learn that language.
The reason is not a single bad book, where probably most programming languages
have a few of.

~~~
rfergie
The reputation rather than the actual experience of Haskell is what puts
people off.

~~~
CJefferson
Here was about my first experience of Haskell. I don't mind admitting I
bounced fairly hard at first. I've since done a bit more, but find it too
limiting rather than freeing.

Prelude> foldr + [1,2,3]

<interactive>:14:9: Couldn't match expected type ‘(a -> b -> b) -> b -> [a] ->
b’ with actual type ‘[t0]’ Relevant bindings include it :: (a -> b -> b) -> b
-> [a] -> b (bound at <interactive>:14:1) In the second argument of ‘(+)’,
namely ‘[1, 2, 3]’ In the expression: foldr + [1, 2, 3] In an equation for
‘it’: it = foldr + [1, 2, 3]

~~~
Viktoras25
Finally I found out the correct version: foldr (+) 0 [1,2,3]

1\. + contains only special characters and must be used either as infix
function (1 + 2) or be enclosed in brackets

2\. You need an initial value for the accumulator. You are reducing a list to
a single value, you need to start somewhere

Please, gurus of Haskell, correct me if I'm wrong, I've just recently started
to learn the language

------
overshard
Most of my hate is not directed at PHP but rather the code of the projects I
run across written in PHP. It's not uncommon for there to be random whitespace
and code thrown everywhere with no heed to a sensible MVC or other software
architectural pattern.

I do occasionally run into well written and maintained software written in PHP
and, while it's not my prefered language, it's quite readable and I can work
with it.

PHP does have it's issues but they are exacerbated by the general community
that uses it.

~~~
skrebbel
> _Most of my hate is not directed at PHP but rather the code of the projects
> I run across written in PHP._

This is pure selection bias. There's great PHP code and there's horrible
$YOUR_FAVOURITE_LANGUAGE code.

If you hate PHP because of this, you must also hate Java (since Android, at
least, which at least halved the average competency of the community) Ruby
(since Rails became too popular), JavaScript (see the jquery thread on the HN
front page right now), Haskell (big ball of 2000 unorganized functions with
two-letter argument names, anyone?), C# (This Is How Microsoft Does It So We
Must Too) and Python (at least since Codecademy/Treehouse started unloading
thousands of well-meaning but inexperienced Python programmers on the world).
Don't even get me started about Perl and C++.

I'm not sure what's left. Clojure, Elixir, Turbo Pascal?

~~~
tormeh
I think it's a bit silly that less-than-four-letter
arguments/values/objects/functions are allowed in modern languages. I mean,
what are the odds that the programmer is not writing horrible code in that
scenario?

~~~
ubertaco
Some trivial counterexamples (in ES6 for convenience):

    
    
        someArray.sort((a, b) => a - b);
    
        var odd = (x) => x % 2 == 0;
        highlightRows = rows.filter(odd);
    
        function isLegalAdult(age, locality){
           ...
        }

------
return0
PHP is awesome. It's so easy, i never had to read a book about it. Powers the
web, and is ubiquitous. Sweet deal, instead of learning 10 different trendy
languages every year, i stuck to it for more than 13 years now, and learned
other much more important stuff. Wanna do something too complex? You wouldn't
use a scripting language for that anyway. There's a tool for everything in PHP
and it's fast. PHP made me money, i havent found something that's better
overall.

------
hewhowhineth
There are only two kinds of languages: the ones people complain about and the
ones nobody uses. - Bjarne Stroustrup

------
TazeTSchnitzel
A lack of decent tutorials and resources to learn PHP is something the
language really suffers from. Google "PHP tutorial" and almost everything you
get is completely awful and uses 12-year-old (as in, from 12 years ago)
programming practices.

Heck, even the PHP manual tutorial is downright awful and desperately needs
updating.

~~~
jbrooksuk
I have to say that Jeffrey Way's Laracasts[1] - which yes, does cover more
than Laravel - is a great place to go to learn really good PHP techniques.

[1] [https://laracasts.com/](https://laracasts.com/)

~~~
hackerboos
It's always surprised me that Jeff has stuck with PHP. The guy is a very
capable programmer who I thought would have moved on to bigger and better
things.

I guess the market for tutorials and learning is larger for PHP than most
other languages, except Javascript, possibly...

~~~
hdra
So you're saying no capable programmer would stick with PHP given the choice?
what makes you think so?

~~~
hackerboos
Because, put quite simply, there are better choices.

~~~
noir_lord
I've been programming since I was a kid, I'm 34 now, I've been selling code
since I was 16 and I still use PHP for the web.

It has an intersection of features (speed of development, ease of deployment,
availability of libraries, availability of programmers) that makes it a
compelling choice _for the web_.

Everything else (except toy stuff) I do in Python.

------
gitaarik
One of the major reasons I dislike PHP is because of the include mechanism.
When you include a file, you literally include the code of that file on that
spot. You can't assign it to a variable to namespace it or something. Also the
file that get's included can use the variables of the file it gets included
into. This allows for some crazy behavior that can be very hard to analyze.

So to keep an overview of what you're including or what actually gets
included, you'll have to make rules like "the filename should be the classname
lowercased" or "all views for this module are in this specific file" and
"included files may never use variables of files they are included into".

A lot of PHP frameworks have these kind of conventions. That's good, people
are less prone to create unclear program behavior, but, it's still possible if
they want. And anyway, it's sad that you need these conventions to help you
use the language in a sensible way.

That's my biggest annoyance of PHP anyway. Don't know how much people feel the
same way?

~~~
eridal
Are you aware that you can include/require values?

file a.php

    
    
        <?php
        return 42;
    

file b.php

    
    
        <?php
        $a = include 'a.php';
        var_dump($a); // (int) 42

~~~
gitaarik
No I didn't know that, that's pretty cool, why isn't everybody using that :P?

------
twunde
I'm now desperately trying to remember the PHP book I read in 2007. It was
nowhere near as bad as the example here but I'm sure it used globals
everywhere and had other bad examples. It definitely reminds me of when I
first tried learning javascript and every example I copied didn't work on my
site. I distinctly remember Blizzard having some sort of moving graphic from
diablo that I tried to just copy and paste into my site.

~~~
drethemadrapper
The best book ever written on PHP was The PHP Anthology 1 & 2 by Harry Feucks.
Those books rock. They were for PHP4 though.

------
jikuri
Hating PHP for ugly code, written by bad programmers is like hating the
english language for talking slang.

------
growthape
PHP is here to stay. Haters gonna hate. Here is some tonic for the haters;
[http://www.cloudways.com/blog/php-
advantages/](http://www.cloudways.com/blog/php-advantages/)

~~~
tupshin
Thankfully it's on a long slow slide to oblivion.
[https://www.google.com/trends/explore#q=php&cmpt=q&tz=](https://www.google.com/trends/explore#q=php&cmpt=q&tz=)

------
eugene-d
PHP developers are much much more qualified than Python/Ruby/Java devs for the
same price in my area. You can hire PHP dev who can TDD for $10/hour. Or you
can have a Ruby junior who brags about Ruby and cannot ship things

~~~
lampe3
10$? and you want a "good" developer? good developer in my area start at 30+
euro

~~~
mauricemir
Id say in the UK the contract rate is more like 60-70 Euros or £50 ph for an
experienced developer maybe -20% for a very junior developer though most
serious contract developers quote a day rate

~~~
lampe3
yeah good senior developer are around 60 to 70 euro here too

------
jbrooksuk
> Including a function like count() or sizeof() within a loops execution
> condition is a bad idea. This expression will be executed with every
> iteration.

I've been told by numerous people that this is no longer the case, the value
is cached.

~~~
scintill76
Yeah, that smells a bit like premature optimization. Anyway, I'd use foreach
as much as possible, avoiding that issue as a side-effect.

~~~
jbrooksuk
I completely agree. Foreach is generally nicer for looping a collection
anyway.

------
gizzlon
Would that counter example even work? Isn't there a race condition? File-
locking?

Maybe they should just add to the file and compact it from time-to-time
instead..

------
michaelwww
Bad code can be written in any language.

------
mahouse
I'd blame some of those things (such as ' -> `) on the editor.

------
drethemadrapper
PHP is here to stay and will have better documentation over time. PHP
programmers will start writing awesome, meaningful and standard code as more
and more languages and tools make it possible to compile code in a specific
language into a PHP code. One example is the Haxe Programming Language. I
jumped onto other programming languages, such as Python and SPA with JS, some
time ago; but I am now investing more of my time in Haxe.

All that being said, I am also wary of the all-in-one kit and its imminent
trouble. I have been seeking comments on it from the public here -
[https://news.ycombinator.com/item?id=9111742](https://news.ycombinator.com/item?id=9111742)

~~~
asmicom
I can't agree more!

~~~
drethemadrapper
Thanks asmicom; I don't think I should be downvoted for expressing myself.
That was my opinion. And I was also seeking comments from readers. @erikb:
There is a school of thought those apps - FB, wordpress,etc - don't contain
lines of code with best practices. I am however glad they are released on non-
restrictive licenses and the general public are contributing to the various
projects.

All I can say is that PHP is here to stay. I have not written a whole
app/project in PHP5 before but with PHP4. I however think kits/tools like Haxe
AND apps like FB & WP will keep PHP in the market for a very long time.

