tags:

views:

946

answers:

5

I am used to writing C# Windows application. However I have some free hosted PHP web space that I would like to make use of. I have a basic understanding of PHP but have never used it's object oriented capabilities.

Is there an easy way to convert C# classes to PHP classes or is it just not possible to write a fully object oriented application in PHP?

Update: There are no reliance on the .NET framework beyond the basics. The main aim would be to restructure the class properties, variable enums, etc. The PHP will be hosted on a Linux server.

+2  A: 

A huge problem would be to replicate the .Net Framework in PHP if the C# class usses it.

A: 

I don't know about a tool to automate the process but you could use the Reflexion API to browse your C# class and generate a corresponding PHP class.

Of course, the difficulty here is to correctly map C# types to PHP but with enough unit testing, you should be able to do what you want.

I advice you to go this way because I already did a C# to VB and C++ conversion. That was a pain but the result was worth it.

Vincent Robert
+1  A: 

It is entirely possible to write a PHP application almost entirely in an object-oriented methodology. You will have to write some procedural code to create and launch your first object but beyond that there are plenty of MVC frameworks for PHP that are all object-oriented. One that I would look at as an example is Code Igniter because it is a little lighter weight in my opinion.

John Downey
A: 

If the problem is that you want to transition to PHP and you are happy to continue running on a windows server with .NET support you might consider wrapping your code using swig.

This can be used to generated stubs to execute from php and you can then go about rewriting the .NET code into PHP in an incremental fashion.

This works for any of the supported languages. ie. you could incrementally rewrite an application in c++ to java if you really wanted to.

JProgrammer
+2  A: 

PHP doesn't support enums, which might be one area of mismatch.

Also, watch out for collection types, PHP despite it's OO features, tends to have no alternative to over-using the array datatype. Check out the sections on the PHP manual on iterators if you would like to see beyond this.

Public, protected, private, and static properties of classes all work roughly as expected.

maetl
+1 for specific examples of possible problem areas.
Beska