I’m sorry but why can’t php be more like C# with ASP.NET?

If you look at my earlier posts, you’ll see I’ve become a bit of a Mac fan but when it comes to programming I’m sorry but you can’t beat Microsoft. I’ve been developing personal sites (such as RetailHealing.com) using php for about 3 years now but in my ‘real’ job I use ASP.NET in C#. You may disagree but I think that gives me an unbiased perspective on the two environments.

Whatever people say about Microsoft, they do create very excellent programming environments. I find Visual Studio easy to work with once you understand the configuration, build and publish model and I’ve yet to find a php development environment that makes programming more straightforward with features such as debugging, dynamic type ahead/autocomplete - I have heard that zend studio is the thing to use for php but I’ve personally not tried it yet.

Now to C# and ASP…

OK, so C# is very much a clone of Java and PHP but that suits me because I was trained in C and the move to Java, PHP and C# took very little time. But what I really, really like about C# and ASP is the way is handles web page processing and particularly forms with the code behind model. PHP is crying out for something like this. The closest tool I’ve found for this is Smarty [www.smarty.net] but what I would really like someone to do is implement the following ASP/C# features in PHP:

Postback handling
Panels
Labels
Validation
Authentication

Postback handing

ASP and C# manage all web interaction with the code behind model. The HTML page (.ASPX) controls the layout while the C# page sits behind the html and control the functional logic. Each time you click a button or interact in some way with the page, ASP initiates a ‘postback’ (actually a web form submit) and kicks off a page load and/or method in the C# code.

Of course, php gurus will say that all ASP is doing is using standard web form processing with some Javascript to do this - and of course it is. But I don’t have to write it, it’s all hidden from me as the developer and I can concentrate on the core logic. This also means that the code behaves consistently.

Panels

ASP:Panel - a great feature that I use all the time. Build a web page consisting of a number of panels - for example, one ‘welcome panel’, a standard user panel, an administrator’s panel and perhaps an error panel. Now, in your code you can make each panel visible or invisible at any point in the flow of the application.

Again, in php you can do this using divs with css and hiding sections as needed but ASP needs way less code to do the same and you don’t end up with hidden divs on the page which Google can frown upon.

Labels

OK, php is similar here. Instead of the php <%=variable %> in ASP you use <ASP:label id=name>but that same label can have serverside code behind it, click events, validation and much more.

Validation

Form validation in ASP is excellent. Need a field to contain something before the user can submit the form? Simple. Just add some validation code to the field along with some helpful error text to guide the user.

Authentication

Finally, Microsoft hasvery advanced in-built authentication and the web.config file which as far as I know, php has no equal of. Tell web.config that you want forms validation using a login page hooked into a user database table and that’s pretty much all you need to do to have a secure website. On each page, just check that the user is authenticated (User.Identity.IsAuthenticated) and that’s it.

I’m probably going to get a lot of flame posts from serious PHP programmers telling me about why I’m wrong and that there are ways to deliver the same functionality in PHP and I look forward to hearing about them. I think there is an audience of PHP developers who really need these features.

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment