9
votes

It is widely believed that PHP is the easiest programming language to learn for a beginner. The argument goes that PHP is the easiest language to use for getting a quick prototype up-and-running.

Why might this be? What, specifically, makes PHP easier to use than other languages?

Would this remain true, even when learning to use the object-oriented aspects of PHP? Or is it actually the object-oriented aspects of PHP that make it easy to learn? How does it compare with other web programming languages?

0

5 Answers 5

25
votes

PHP is native to the web. While Ruby and Python have much cleaner syntax, more elegance, and more power, there will always be a layer of abstraction between Ruby/Python and the web itself -- after all, they were designed for much wider domains than the web.

Newbies to programming are typically newbies to sysadmin, and getting to Hello World in a Rails or Django is pretty painful -- for some even prohibitively so -- compared to PHP.

For newbies, it's easy to conceptualize that typing in:

http://mysite.com/something.php

...will execute the code stored in the file:

/path/to/mysite's/webroot/something.php

This simple one-to-one routing also mirrors that of HTML and other static files.

Beware, however, because this one-to-one routing also leads to security problems (i.e. people tend to keep all of their executable code within the webroot -- even secure code, which may contain passwords, hash salts, and other Privacy-Important code). Combine this with a lack of sysadmin experience, and many sites on the web are a chmod away from being totally exposed.

Responsible PHP like Symfony helps people avoid this, but Symfony requires the same level of sysadmin chops as Rails and Django.

2
  • 1
    Ruby doesn't predate web. There just isn't any reason why such a thing as the web should influence the design of a programming language. Otherwise, nice answer. Jan 15, 2011 at 14:34
  • You're right! Although I would argue that domain can and should influence language design in some cases ;)
    – Kyle Wild
    Feb 11, 2011 at 2:09
7
votes

Object oriented programming is optional

PHP is forgiving
The script continues running on minor faults.
When E_NOTICE (or even E_WARNINGs) are suppressed, the errors aren't even noticeable.

But also in the small things like substr: In C# you'll get a big fat exception when you'll try substr($text, 3) on a $text with 1 character.

Great online manual
http://php.net/manual/

Quick and Dirty is the default
The language is filled with useful shortcuts.
PHP lets me express what I want without typing an essay.

6
  • 3
    Actually, OO is optional when working with Ruby or Python as well.
    – Kyle Wild
    Jan 15, 2011 at 14:24
  • 1
    But in ruby/python the basic types: int, string, etc are objects.
    – Bob Fanger
    Jan 15, 2011 at 14:32
  • The design of the language itself (ruby, for example) is oriented around objects. PHP is not. Your application can be object-oriented, but the language itself, at its core, is not. As such, you can write entire apps in PHP without ever touching objects. You can't in Ruby, because core things (string, int, etc) are themselves objects and you have to call methods on them to do anything.
    – kimsal
    Jan 15, 2011 at 16:35
  • I would think, that for a beginner, less forgiving language is better, it helps to learn. What matters is handling of errors and contents of error messages. Feb 10, 2011 at 23:24
  • Learning to become good programmer isn't the main goal. Getting something working is. (easy != best_learning_environment)
    – Bob Fanger
    Feb 11, 2011 at 15:26
5
votes

Conceptual simplicity.

A php site can consist of one file representing one page, with the dynamic content embedded within the static markup as needed. You can scan down a simple php file and see everything defined and run sequentially.

With a simple php site, there is no learning curve where one has to figure out in what file a specific piece of logic belongs, or in what external file a function has been defined.

...

Of course there is a reason that frameworks like rails provide lots of files and a fixed structure, and I would definitely recommend using one for any sizeable (and probably almost every small) site.

I do think though that it's this very low barrier to entry that is responsible for a lot of php's popularity.

I don't think that there's any reason a better php style system couldn't be written in ruby or similar - think just directories and .erb and .haml files and nice 4.days.ago syntax. But most people who could do this see the value in the extra tools that a framework provides. Sinatra is a minimal framework, in which it's possible to define an entire site in one file, but even it has routing powered by code instead of just directory and file naming.

1
  • I think that even this is addressed in Ruby through the Sinatra ramework, which allows same kind of entry level complexity. Feb 10, 2011 at 23:20
2
votes

PHP have many web tutorials and books about it, it's free and popular which makes PHP communities bigger. And also it's intuitive.

1
vote

While PHP is far from the best web programming language, it's the most common (in terms of availability in hosting packages), the most popular (even in things like tags here on SO), it has some of the best documentation, and it's one of the least strict in terms of having to follow any sort of standards.

Not the answer you're looking for? Browse other questions tagged or ask your own question.