Brief comparison of PHP and ASP Dec04 '05

(I understand that this entry is, perhaps, five years late, since ASP doesn’t have the "hype" surrounding it, like it once did. However, that doesn’t change the fact that I have to use ASP at work, on a legacy system.)

I’ve been using ASP at work, and other than it being a completely out-dated language, there’s so many little differences (annoyances), as compared to PHP.

To be fair, there are more things that aggravate me with ASP - but there is also the occasional benefit, over PHP.

Some things I’ve noticed immediately:

No "quick" operators

When you need to set a variable to itself, plus whatever:

PHP: counter += 1;

ASP: counter = counter + 1

Just that extra typing is aggravating.

No "total rows" function after a query

To grab the total number of rows returned from a database query:

PHP: mysql_num_rows()

ASP:

 
counter = 0
while not result.eof
    counter = counter + 1
    result.movenext
wend
result.movefirst

response.write counter

Need I say more?

Formatting code

Formatting code (new lines, tabs) is also more to write:

PHP: " My string\n\n ";

ASP: " My string " & chr(10) & chr(10)

Once again, lots more to type.

Equal sign in conditional testing

PHP:

if ( $counter == 0 )
{
    ...
}

ASP:

if ( counter = 0 ) then

    ...
    
end if

Notice the double equal sign, for PHP, but a single equal sign for ASP. This is a subtle shift in thinking, which has tripped me up on occasion. ASP, in fact, does it the more intuitive way, but I have become used to PHP’s double equal signs.

Passing variables across pages

Passing variables across pages is almost easier with ASP.

Coming from a form: apples = 10

Coming from the URL: /index.php?page=2

Ignoring the .php part of the URL above (cuz it could also be .asp)... in order to access both variables (apples and page) from another page:

PHP: $_POST["apples"]; and $_GET["page"];

ASP: Request("apples") and Request("page")

Notice how ASP uses Request for both situations (GET or POST), whereas PHP uses either $_POST or $_GET. Just a subtle distinction.

No associative arrays!

This is the single most aggravating feature of ASP - no associative arrays. I can’t tell you how useful associative arrays are.

OK - so ASP still allows for numerically-indexed (one-dimensional) arrays... but hardly any array functions!

For example, if I simply want to sort an ASP array in alphabetical order - no can do. I’d have to come up with some crazy home-made function to achieve order.

With PHP - go to town. There’s a smorgasbord of options.

PHP vs. ASP - which is better?

Obviously ASP is no longer being developed by Microsoft, which was a strange decision on their part. Instead of giving programmers and developers a nice, simple language, of which to "compliment" their HTML code (like PHP) - they took that freedom away.

So, these days, you either have to use a full-bloated framework, like ASP.NET; use an out-dated language like ASP; or you just don’t develop web sites with a Microsoft technology.

I have nothing wrong with Microsoft technologies - it’s just they always want to "tie you down," and make you completely rely on their products - and only their products. As if the future will always consist of Microsoft.

PHP is open-source, free, and contains 10 times the amount of resources (on the web) than ASP does. PHP is continually updated with newer versions, and it has many extensions (like PEAR) that make it a very appealing language. It also runs on almost every OS imaginable. Ever run ASP on Linux? I doubt it.

As far as the "nuts and bolts," if you have a basic understanding of programming principles, either language will do.

As far as syntax and style of each language - there is truly no "major" difference. You got variables, functions, arrays, conditional statements, etc. The components and tools are the same.

If you can visualize what you want to do - it’s just a matter of finding the right keywords to use.

Whereas (off the top of my head), I am more efficient with PHP - that’s only because I’ve come to memorize many keywords.

ASP requires me to lookup stuff, but only because I don’t know the specific keyword used.

Categories: PHP , Programming , Web Development

Add Feedback (view all)

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

You can use $_REQUEST in php. This takes into account $_GET, $_POST and $_COOKIE. http://www.php.net/reserved.variables ... Read more.

Interesting... thanks Dale. Another example of the versatility that PHP has over ASP. ... Read more.

Mmm... dubious about the security of such versatility, though. PHP has earnt a bad rep for such things, even if people generally consider IIS/Micro ... Read more.

PHP Security to the rescue! ... Read more.

A little late to the game, I realize, but just in case anyone happens to come across this via Google... No "total rows" function after a ... Read more.

Hi, Great post. I use both PHP and ASP and have to say you are almost spot on in your comparison of the two. Here I look at ... Read more.

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Contact Matt

Similar Entries

Stats

120 unique visits since August 2008

Syndicate

Advertisements