Why is PHP considered to be the easiest web programming language to learn? [closed]
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?
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.
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.
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.
PHP have many web tutorials and books about it, it's free and popular which makes PHP communities bigger. And also it's intuitive.
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.
精彩评论