Revision 3 as of 2006-10-19 18:06:07

Clear message

This page was copied mindlessly from http://72.14.203.104/search?q=cache:bo4LWB1ZHswJ:wiki.w4py.org/python-vs-php.html+php+vs+python&hl=en&gl=us&ct=clnk&cd=1


Common Ground

Both PHP and Python:

Compared as Languages What does PHP have that Python doesn't?

What does Python have that PHP doesn't?

Compared as Web Development Frameworks

Unlike PHP, which has web development features built directly into the core language, Python's web development capabilites are provided by add-on modules. Basic CGI capabilities are provided by the 'cgi' module which comes in Python's standard library. There's also a wide range of third-party modules available for Python; some are complementary, others compete. As a result, Python provides a more flexible base for web development.

There are some adverse side effects of this flexibility. First, the range of choices can be bewildering. Unless you are working experienced Python web developers, PHP is easier to get started with. Second, support for PHP is more common with shared-hosting companies than support for the various Python options.

Another difference is that PHP is embedded in the web server, whereas Python web applications can either be embedded in the web server like PHP or run in a separate process. Here's a simple classification of Python web development platforms:

(Note: PHP programs can be run standalone or as ordinary CGI scripts. However, when called indirectly from the web (e.g., from a Perl CGI script), it requires unsetting an undocumented number of web environment variables so that PHP doesn't think it's running from the web and look in the wrong place for the script. Likewise, it's _possible_ to write a long-running server in PHP, but there are precious few examples of it.)

The vast majority of Python web applications are run in a separate process. This has some important implications. ... to be continued ...

... please add your observations Python Application Servers

... Python Template Engines

...

Here's some interesting notes on security in PHP: http://www.securereality.com.au/studyinscarlet.txt Community Support

PHP

Python

Commercial Support

PHP

Python

Documentation Core Documentation

Although both PHP and Python have excellent core documentation, Python's is more extensive and generally higher quality. PHP has a large number of translations available. Python doesn't. For PHP see http://www.php.net/docs.php and for Python see http://python.org/doc/ Python allows documentation on modules, classes, and functions to be included in the program code. The documentation becomes an attribute of the module/class/function, accessible from inside of the language itself. Python manual is really awfully structurized and presented compared to PHP manual, which uses cross-links, a lot of colorized examples and invaluable user comments to make it easier to comprehend the magic. PHP manual merges different versions of the language together making it a little bit bloated.

Online Tutorials

For Python see http://python.org/doc/current/tut/tut.html and http://python.org/doc/Newbies.html

For PHP see http://www.devshed.com/Server_Side/PHP/, http://phpbuilder.com and http://zend.com Books

For books on PHP see http://php.net/books.php?type_lang=PHP_all . For Python, see http://www.amazon.com/exec/obidos/tg/listmania/list-browse/-/12QMUFII6951W and http://www.awaretek.com/book.html Conclusion

... Frequently Asked Questions

Q1

A1

Application Servers:

Templating Engines:

My personal preference is Apache/Webware/Cheetah. I'll write more about this later. -- TavisRudd? - 23 Nov 2001 General Discussion

(add your comments here, along with a signature and date)

I haven't used PHP with XML, and I've only used Python with XML a little, but I get the impression Python is much better suited -- specifically because it is strongly types, where PHP is rather weak in its typing (like C). But I can't say from experience

-- IanBicking - 26 Nov 2001

To clarify, PHP's types are more dynamic than Python's. All variables are automatically initialized to NULL. It automatically converts between strings, numbers and NULL when a different type is needed for the operation, or with a type case. It also "does something" to convert to/from array and object. '123' -> 123, 'non-numeric' -> 0, NULL -> , etc. Sometimes all this is convenient, especially when a missing CGI param converts to NULL which converts to in the VALUE= attribute, but it also leads to wrong ouput rather than errors if you misspell a variable or key.

PHP does not have first-class functions. There are equivalents to Python's map, reduce, filter, and there's array_walk, but they all take the name of a function rather than the function itself.

Examples of PHP's schizophrenic function naming: (string functions) stripslashes vs strip_tags; (array functions) array_keys vs asort vs count and shuffle; (variable functions etc) isset vs is_array.

PHP has constants, which are initialized with a totally different syntax than variable assignment. The advantage of constants is that they can be defined only once, allowing you to define sensitive constants in a secure include file, then prevent untrusted code from overriding them. Constants are global: they bypass the scoping rules. One disadvantage is that a constant is a bare word: if you misspell it, you'll silently get a NULL value (it's not true: you get misspelled name as the value and a "notice" information (usually not displayed)).

Syntax errors show the file and line number, but not the character position. Sometimes the error message is specific, sometimes just "parse error". This leads to staring at the code for a while until you realize you're missing '$' or ';', or you put something besides a semicolon on the END line matching <<<END .

-- MikeOrr - 15 Dec 2001

Unable to edit the page? See the FrontPage for instructions.