PHP and ASP.NET – Making the right choice

If the past debate between PHP and ASP.NET was thought of as a biased comparison, due to the fact that the first was a scripting language, and the latter a fully developed web application framework, now the issue is a bit easier to discuss, since PHP has finally added a few OOP capabilities (still not a fully grown platform, but anyway an improved one).

ASP.NET is a web application framework developed by Microsoft into the basic CLR of .NET, which allows programmers to build dynamic web sites, web apps, and web services, by writing ASP.NET code using any supported .NET language. PHP, on the other hand, does basically the same thing, but in a different way. While there are similarities, it’s the differences between the two that matter – but when things lack simplicity and clarity, a lot of myths and misconceptions are likely to show up, and this is what happened with both these technologies over the years. Like if it’s free, it’s just the same as good (or even better) to build a website. Or, if it costs, then it’s just a capitalist instrument.

Set naïve opinions aside, the basic questions that a manager should ask concern the licensing issues, the cost-effectiveness of the servers, the availability of skilled workforce, and the security level provided for the company infrastructure.

Read the following sections of this article to find out more about the technical features of both PHP and ASP.NET technologies, and how ASP.NET can improve the efficiency rate and standards of a dynamic website.

The new OOP additions in PHP 5

The community evolved around PHP has helped the scripting language reach the 5th version in July 2004, in which they have included various object oriented features, resulting into a better language that can provide sophisticated Web-based applications.

In the area of object oriented features, PHP 5 passes objects by reference, which is more efficient than having to duplicate memory structures. The 5th PHP version offers extended object-oriented support (such as providing the  INSTANCEOF keyword), and better constructors and destructors. It also provides private and protected variables and other popular OOP features, such as abstract classes (which enable developers to build prototype classes).

Other syntax improvements include the FINAL keyword, which prevents the subclassing of a member function, the  CONSTANT keyword, and complex exception handling with the  TRY, CATCH, and THROW keywords. As an example, in an error occurred during the execution of a program, if TRY was used, then the  CATCH section should warn the developer about it.

Another included functionality is function overloading, which allows developers to create several different implementations for the same function, while using different input variables. This is different from using default values, which are used only when arguments are not specified. The important aspect about this feature, is that the programming engine will determine which function was meant to be called, at runtime, according to the types of the variables used to call it.

The latest PHP version is clearly a useful tool. Coupled by the fact that it’s released in the open source community, it appeals to a wide range of developers that would rather choose a development environment with less restrictions on implementation and lower costs, over a more competitive, professional development tool like ASP.NET.

The bottom line in free versus licensed development languages is about improvements, and although PHP and other open source programming tools are constantly upgraded by their communities, these upgrades are nevertheless slower and bulkier, since they are made by different groups of persons scattered over the web, with no central management control or supervision.

Which brings us to a fundamental issue in website management. As we entered the year of 2009 in the gloomy horizon of the world wide financial crisis, many businesses are trying to cut costs by moving to open source, no costs servers and development tools. This is effective in terms of financial costs, over the short term, but when we speak in terms of human resources (training, getting people to work in PHP, lowering turn-over rates) may result in higher costs over the long term than previously expected. Well, maybe a lot of people will start liking PHP better so this will not be a problem, but then again, it’s hard to count on people’s likes and dislikes when a business is at stake.

Another major concern would be the liability issues. When using free stuff for your business, don’t expect for someone else to be held responsible when things go wrong. Because there isn’t any “official” contract between you and open source creators. Whereas, in a binding contract between a supplier (Microsoft) and the business owner, the latter is secured against failures by Microsoft’s liability for its products. This explains the higher costs of .NET servers. But costs are not the only thing the .NET technology is known for. Keep reading to see what ASP.NET actually provides for developers.

What ASP.NET provides on top of that

One of the great advantages in .NET technology is the editor, Visual Studio .NET IDE. Usually, a good IDE can turn seasonal programmers into permanent ones, or make those who work part-time more productive. It’s a like a constant teacher, nagging the developer about what goes wrong, highlighting syntax, completing the commands, and organizing the code better. It also has an efficient debugger, which means a lot when working with newly emerged developers, but also with experienced ones, because it takes a lot of the “mechanical” stuff off the programmer’s shoulders. Faster coding translates, of course, into an increased  productivity – and then, what any manager loves to see: better payoffs.

The .NET framework on which ASP.NET relies provides classes for markup abstraction, which translates into an easy generation of HTML code appropriate for the browser that is used for connecting to the web site. This means that developer can go on accessing the respective site through any type of browser, the standard HTML browsers as well as the mobile browsers (hosted e.g. on a PDA or a WAP phone) – without having to render the various markups that are needed, because the .NET framework deals with this by itself. Although the developers have to rely on Microsoft’s choices in terms of handling browser compatibility, still .NET provides the same flexibility as PHP, i.e. the developer is free to write personal HTML libraries, while managing different stylesheet classes for different clients according to his own will. In the end, the ASP.NET native support for cross-browser compatibility is far more extended than the one provide by PHP.

The latest .NET versions bring added functionality to all .NET languages. .NET framework 3.0 includes a set of managed code components that are an integral part of Windows Vista and Windows Server 2008 operating systems. This release includes four major components, starting with the WPF, or Windows Presentation Foundation, which is a new user interface subsystem and API based on XML and vector graphics that uses 3D computer graphics hardware and Direct3D technologies. It also includes the WCF, or Windows Communication Foundation, a service-oriented messaging system which allows programs to inter-operate locally or remotely, similar to web services. The other two components are Windows Workflow Foundation, WF, and Windows CardSpace, which is a software component that stores a person’s digital identities and provides a unified interface for selecting the identity for a particular transaction.

The last version released for the .NET technology, .NET 3.5, was in 2007, and includes added properties to the Base Class Library classes, as well as language improvements such as the Language Integrated Query, or LINQ. LINQ can define a set of query operators that can be used to query, project and filter data in arrays, enumerable classes, XML, relational database and third party data sources, allowing any data source to be queried.

In every argument between .NET and PHP things turned to code compiling. We all know that .NET compiles code, like C#, into a language dubbed Microsoft Intermediate Language (or MSIL in short), that runs on machines through a runtime environment, the .NET Common Language Runtime (CLR). It can be reasonably compared to Java’s bytecode (the code resulting after the primary source code is compiled). PHP, on the other side, can not really offer a match for MSIL, since PHP is basically a script that is interpreted at runtime. For those who care about interpreting vs. compiling, there’s not much to be said – interpreted languages are simply way slower than compiled ones.

But, both with PHP and ASP.NET,  a web server can be configured to do connection pooling and caching pages hosted there, in order to avoid recompiling pages every time. In this way, one can not be strict in saying that PHP is exclusively interpreted, while ASP.NET is compiled. PHP tries to match ASP.NET by occasionally using pre-compiled code sequences, or various optimizers such as Zend, but let’s face it, they don’t always work as expected, and anyway they require some effort for finding and setting up (whereas in ASP.NET’s case, it all comes with Visual Studio, no setup effort required).

PHP features

The PHP acronym initially stood for Personal Home Page, but latter, as the technology evolved, it was re-packed as PHP: Hypertext Preprocessor (using the famous recursive initialism). A side by side comparison between PHP and .NET would raise the following points:

  • PHP can not really be compared to .NET – the latter is an application framework, while PHP is a programming language. In this way, PHP can rather be compared to various languages that run under .NET (and allow the creation of ASP.NET applications), such as VB.NET or C#.
  • PHP, just as any .NET language, is an appropriate solution to building a website. The question revolves around the efficiency, size and complexity of the website you want to build.
  • PHP has support, but not accountability. Let’s get things straight. “Accountability” stands for one person’s (or corporation’s) binding liability for the product it offers, whether free or not. The communities around PHP, although numerous, are not bound by any contract, or legal form, to the PHP user.
  • For average websites, PHP can offer object oriented scripts, applied on a “used whenever needed” basis. This perspective is time inefficient on the long run.
  • PHP has various open source tools that can imitate the .NET template mechanism and web development features.
  • PHP has a down-to-earth approach, that is useful and appealing to young programmers, or any person interested in creating a basic website. If  the website is desired to be more dynamic, then PHP will require time, documentation and experimentation (so it’s usually an individual learning process), and this turns interested persons into seasonal programmers.

To understand in what way ASP.NET outpaces PHP, check the next article in this series, detailing the ASP.NET specific technical features.

ASP.NET features

Because they are compiled, applications in ASP.NET run faster than PHP ones.

ASP.NET is written using real object oriented programming languages (C++, VB.NET, C#), while offering multi-language support. ASP.NET applications can be written in any language from C++, C#, Visual Basic, Jscript, Python, Java, Perl, COBOL, Eiffel and Delphi. This results in easy code mixing, objects being instantiated in one language from classes written in others. More languages increases the possibility of finding programmers for ASP.NET projects, as well as finding pre-written classes.

Microsoft has released a series of free development environments for .NET and ASP.NET, called Visual Studio Express Editions. The Web Edition has a built-in Web server, FTP integration and a database administration interface. Microsoft has also released SQL Server Express, a free development edition of the MS SQL server.

Visual Studio .NET can automatically create reports and diagrams for databases. It can debug the code line by line, while simultaneously watching what happens in the application. It can assign a new value to a variable during debugging, in order to test different possibilities.

ASP.NET offers access to the .NET framework class library. The .NET framework offers over 4500 classes that include rich functionality like XML, data access, file upload, regular expression, image generation, SMTP mail etc. other functionality offered by the .NET framework can count the following:

  1. ASP.NET web forms. These available forms support a large variety of server controls. A programmer can also write his own user or server controls.
  2. Out-of-Process session state. Session variables are no longer lost if a website is restarted or even if the server is restarted, offering improved Web site reliability.
  3. Business objects can be created through .NET (compiled DLLs) for Web applications.
  4. XML web services. Inter-operable web services can be created to communicate and share data over the web, without minding the operating system or the programming language.
  5. ADO.NET support provides consistent access to data sources like the MS SQL server, or data sources exposed via OLE DB and XML.
  6. ASP.NET offers alternatives to ASPMail or ASPUpload, while also enabling new functionality like image generation, encryption and others, functions that in the past required third-party components.
  7. With ASP.NET Mobile Internet Toolkit a programmer can target cell phones, PDAs and other mobile devices with relative ease. Over 80 mobile devices are supported with just one code base. So, based on the requesting device, ASP.NET automatically generates the suitable WAP / WML, HTML or iMode code.
  8. Code written in any edition of Visual Studio (including the free Web Edition), Dreamweaver MX and others, works fine and is supported on any ASP.NET-enabled servers.
Scroll to Top