

What PHP Needs - davidcoallier
http://phpneeds.orchestra.io/

======
giberson
PHP needs a champion, a Douglas Crockford and book entitled "PHP: The good
parts".

PHP faces a lot of similar discrimination that JavaScript did for the longest
time. Sure, there are still criticisms for JavaScript but for the most part
people have settled and realized that to make JavaScript good you have to
write good code. Which is exactly the case for PHP.

The trendiness of PHP bashing exasperates the actual issues of PHP which can
easily be abated with good practices.

We need a call for someone to get up and preach the best practices of PHP. And
with that, a call for PHP Lint based on those best practices. There are a few
individual attempts at providing JS Lint type analysis for PHP files but
nothing from anyone with clout. We could use an official analyzer supported by
recognized field leaders pushing quality coding practices.

~~~
tjogin
Absolutely, if PHP has good parts, I want to know what they are.

~~~
Scriptor
It looks like the book for that is already out:
<http://oreilly.com/catalog/9780596804381>

~~~
rjbond3rd
I found that book to be disappointing, not up to O'Reilly's standards, and
certainly not in the same league as JS: the Good Parts. I guess they rushed it
out to capitalize, which is a shame.

------
sigzero
PHP to me is a hodge podge of ideas all thrown together with no real
engineering sense behind them. That might be just how I feel though.

~~~
ch0wn
> That might be just how I feel though.

No, I got the exact same impression. PHP is a language that takes away all the
fun in programming for me.

~~~
glassx
I believe that this (ideas thrown around) is the truth, Rasmus Lerdorf comes
across as a very pragmatic developer who's more interested in getting things
done rather than being an architectural perfectionist.

But I'm not saying that in a derogative way. Coming from C#, Java and Ruby, I
feel that PHP is kinda fun and refreshing. The object model is quite simple,
and I love the $$ (variable variable) syntax, and how 'reflection' is way
simpler than any other language. It's language for hackers.

~~~
jessedhillon
Reflection is simpler than _any other language_?

Here's an example from the PHP docs on the reflection API, in the comments:

    
    
      $a = new A();
      $reflector = new ReflectionClass('A');
      $properties = $reflector->getProperties();
    
      $i =1;
    
      foreach($properties as $property)
      {
        //Populating properties
        $a->{$property->getName()}=$i;
        //Invoking the method to print what was populated
        $a->{"echo".ucfirst($property->getName())}()."\n";
       
        $i++;
      }
    

You have to instantiate _another object_ to inspect the first one! Here's
Python, just as an example. (Most languages would be simpler. As with most
things, it would be difficult to find a language where reflection was more
clunky than in PHP.)

    
    
      a = A()
      for i, key in enumerate(a.__dict__):
        setattr(a, key, i)
        f = getattr(a, 'echo'+key.capitalize())
        print(f())
    
    

On another thread somewhere, someone once suggested that PHP is actually Blub
-- a fictional language whose immense and inherent superiority cannot be
explained, only experienced.

As a long time PHP dev, let me assure anyone who thinks that this is the case:
in no way is PHP Blub.

~~~
Zak
"Blub" isn't a fictional superior language; it's a fictional average language
probably imagined to be similar to Java. It was, so far as I know first
described here: <http://www.paulgraham.com/avg.html>

PHP is Blub in the sense that it is not the most powerful language[0], and
some of its users decline to recognize that other languages have advantages
over it. From my perspective, there can be no perfect language; certain
characteristics are more optimal in some situations, less so in others and
mutually exclusive. Type safety and certain kinds of dynamic behavior are an
example.

[0] I'm not claiming here that any specific language _is_ the most powerful,
just that PHP certainly _isn't_.

~~~
jessedhillon
Yes you're right, I got the Blub parable wrong.

What I mean is that the commenter believed that all other languages are Blub
to PHP, as in, PHP is higher on the spectrum of powerful languages and other
language users did not realize that they were looking up when they looked at
PHP.

------
angerman
Just an Idea. I think what causes so many sentiments against PHP is due in
part to the mass adoption of PHP.

These days, you find PHP almost everywhere. And how do you get to PHP? Let's
assume we are in collage and want to write that next big website that's surely
going to rule them all.

Now, we don't really know that much about all this "tech" stuff. But hey, I
can hit "show source" in the browser. This must be easy. After a few baby
steps with a WYSIWY(WishYoud)G tool, you decide to learn /some/ HTML for good.
Once you figure that HTML alone can't do a lot, there's a somewhat native path
to PHP.

You keep on reading tutorials written by others, who know as much as you or a
little more. You are still on the cheap side, and need to keep tight on your
money for that next big website you are going to write.

And the more you read the more enlightened you feel. Wow! I can actually do
that and my dead cheap webhost offers PHP as well. Life is good.

Because you don't lack any minimal intelligence, you figure out how to write
your next (big) website. You probably didn't succeed in writing the next
FaceBook, but hey, you are now /one/ of the /web guys/. You probably think
what you are doing is real fun.

There are then two paths you can take: \- A: stick with PHP and feel
enlightened all the way, when ever you learn some new trick, or \- B: wonder
if PHP is the only true real thing. You don't know C or some other "ancient"
language, so you are still a little afraid. Perl seems to look a lot like PHP
but it's syntax is confusing and no one of your friends on the forums you are
frequenting is using it anyway. Then there is Python or Ruby. Wow those look
strange. No curly braces for function bodies. Why do people here talk about
templating? What's this about? Do I need that? PHP was so easy... Anyway, you
are still curious and learn about this "other" way of writing webapps (that's
what we are still primarily concerned with). Once you start to figure out that
variables do /not/ have to start with $ to be valid, you wonder what else PHP
might have hid from your novice learning? There is a lot more. Not necessarily
PHP's fault. Just the lockin in that PHP mindset.

\----

The basic problem with PHP (to me) is that I've seen it to be more a motel on
the way to enlightenment. Some just find it too comforting to move on. Others,
once they've passed it, rarely(ever?) come back unless someone else tells
(forces) them to do so.

------
leftnode
I almost posted a new Hacker News story, but I saw this and figured my blog
post belongs here better. It's an old post I dug it.

<http://leftnode.com/entry/what-php-needs-to-change>

~~~
qixxiq
I agree with most of the changes on your list, but to be honest (as I'm sure
you're aware) what you're suggesting is not a viable solution.

It would be far easier and more effective to simply create a new language
based heavily on the good parts of php.

------
ivanbernat
I'd be happy if we moved to "+" for string concatenation and "." for object
member access (but this would break every script out there). Though I've been
a PHP user for 5+ years, I still do this when switching back from longer JS /
Ruby development periods.

------
skrebbel
Why the hell does this site need to be able to read my Twitter direct messages
for me to be able to cast a vote?

~~~
simonw
It doesn't want to read your Twitter direct messages.

Here's what's going on. The Twitter API currently has two levels of
permission: "read" (can access your data, which includes your tweets and
followers even if you have a private account, and unfortunately also your DMs)
and "write" (can update your account, including posting new tweets, adding new
followers, creating new lists etc).

Most Twitter users were unaware that granting "read" access to an application
gave that application access to their DMs. This was a problem. Twitter opted
to solve it by introducing a new permission level, "direct messages", which is
write-plus-direct-message access. They plan to remove the direct message
ability from the "read" access.

To give developers time to fix any apps that this would affect, the switch-
over date for direct message access is set to June 30th.

Up until that date, the Twitter OAuth authentication screen includes copy that
tells you that the application will be able to access your direct messages
until June 30th.

This does NOT mean that the application author intends to access them - it
just means that the permission level you are granting gives them that ability
up until the cut-off date.

This issue is a big problem for people like us ( <http://lanyrd.com/> ) who
use Twitter for authentication, because it scares away potential users. At
least after the 30th we won't have to worry about the DM clause, but we'll
still suffer from users assuming that we're going to tweet on their behalf.

Unfortunately, we need "write" access so that the follow buttons on our site
work (Twitter's new JavaScript follow buttons aren't appropriate for our
attendee directory because we show 20 people on a page:
<http://lanyrd.com/2011/europython/attendees/> ) - we also need "write" access
for our currently-in-alpha Twitter list management features.

The best solution I can think of would either be finely grained permissions
(so we could ask for list and follow access but not send-a-tweet access) or
the ability for us to specify a reassuring message to be displayed on the
Twitter OAuth screen clarifying our intentions.

------
citricsquid
"What PHP really needs is: Strong leadership and an official process to submit
new ideas, extensions", "New blood, and less old blood.", "A plan for the
future of web development".

PHP is an opensource project: volunteer!

~~~
daeken
PHP is an open source project, sure. But really, have you ever tried to
volunteer for the PHP core? I've never gone through a more painful process --
so much political bullshit, resistance to change (even backwards-compatible
change), and echo chamber nonsense. I attempted to volunteer on PHP for a long
while, but finally realized it just wasn't worth it and gave up.

~~~
Produce
Someone should fork the damn thing.

~~~
sc68cal
Someone did.

<http://news.ycombinator.com/item?id=2640756>

Self plug: I cleaned up his original repo and put the patch against the
official PHP git repo.

<https://github.com/sc68cal/php-src>

------
wccrawford
I'm disappointed in the people who put disparaging comments in as ideas, and
the people who voted them up.

This was an attempt to generate awareness and that kind of behavior doesn't
help anything.

~~~
ChiperSoft
The lack of commenting and downvoting means this list will lack any kind of
real curation. There's several large blocks of text on the popular list that
should have been submitted as multiple items.

------
jessedhillon
WARNING: Frank opinions ahead.

I added "To die", because that's my honest opinion after having been a PHP dev
since ~PHP3. Whether it's the language's fault or not, my experience with
other people's PHP code is that anything big tends toward spaghetti except in
a few well-engineered cases. Non-pasta is the exception that proves the rule.

People who actually know something about programming well, frankly, would not
start new projects in PHP. Its only use to me is as a litmus test -- if your
answer to "What do you think of PHP" doesn't include a significant critique of
the language, I probably wouldn't like working with you. (Nor you with me)

~~~
wvenable
There's nothing inherent in the language that makes building non-spaghetti
code difficult. All the weird annoyances and idiosyncrasies are a big pain in
the ass but, unlike say COBOL or Basic (or even C), they don't fundamentally
prevent you from building nice organized easy to understand code.

That being said, I totally agree with you -- other people's PHP code tends
towards spaghetti in the vast majority of cases. My take from this is that if
PHP were to disappear tomorrow all these programmers building spaghetti would
just inflict their level of skill on other platforms.

~~~
Zak
_There's nothing inherent in the language that makes building non-spaghetti
code difficult._

Technically, that's mostly true. Culturally and psychologically, I'm inclined
to say it isn't. Just as you're more likely to leave things lying around
haphazardly in a room that's already messy, you're more likely to write sloppy
code in a sloppy codebase. When the language itself feels sloppy, it's damn
hard to avoid that effect.

Sure, you can write good code in PHP, but why would you want to when there are
so many other languages out there? The only reason I can think of is if you're
selling a product to be deployed on shared-hosting websites belonging to
customers.

~~~
MatthewPhillips
PHP is the default web language. If you're pitching to a client who expects to
maintain the code once you're done and you suggest Clojure, Node.js, or even
_Ruby_ in a lot of cases you won't get the gig. By doing so you've raised
their costs; PHP programmers are easier to find.

This is the main reason I'm not doing web consulting!

~~~
Zak
_By doing so you've raised their costs_

I don't think that's actually true, aside from maybe $10/month extra in
hosting[0], I think costs tend to be lower with not-PHP. Using PHP greatly
increases the probability that a random contractor will be a bad programmer
who will write things that are broken, require more billable hours to get
things done or make a mess that slows down the next guy.

I've never lost work due to suggesting not-PHP to a client. I have, however
regretted failing to do so several times. I've come to believe that a client's
insistence on using PHP is nearly as much of a red flag as a programmer not
knowing anything else.

[0] If a client is worried about $10/month extra in hosting costs, you'll
probably also have to fight them for every dollar. They might even try to get
out of paying what they agreed to. I've had it happen.

------
noduerme
This is ridiculous. It's like saying hammers should include screwdrivers. Just
know your toolbox and you won't have a problem.

PHP is great. What's with all the hate? It's a good tool for a certain kind of
job, not the right tool for others. Big deal. There isn't a single language
that you can't find bones to pick with. It's all about what you do with it and
how you like to code. If you're comfortable writing server-side script in
brainfuck, more power to you.

~~~
dexen
_> What's with all the hate?_

Some people want every language to be just like Java, so they can switch
between languages with little to no effort -- never mind we'd have only Java
in the end.

Some people want everything abstracted out, so no implementation details have
to pe paid attention to -- nor leveraged, ever.

Some people won't believe a language supports something until there's a class
explicitly named after it (``proper unicode support'' my ass -_-').

Some people believe an object wrapped around something will magically make it
better (``a core object that represents the HTTP Request and Response'').

The list goes on...

Please let PHP remain PHP, at least let it retain the good parts :-)

~~~
noduerme
So, uh, can't we all just get along? I mean, I could make a list about why
Java's a nightmare, or Javascript or C# or something else, but if I were
hiring a coder who said, "yes, we must write this server in Neko" I would say,
"okay, why?" And if the reasons were good, then great. Do it. These are just
tools. You should never lean on them for something they weren't designed to
do; but if you find that one matches the job, then use it!

------
mehlah
Love!

------
cschiewek
A final nail in it's coffin.

