7

I am used to writing C# Windows applications. However, I have some free hosted PHP webspace that I would like to make use of. I have a basic understanding of PHP but have never used its 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 is 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.

4

5 回答 5

5

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.

于 2008-08-19T04:07:39.110 回答
3

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

于 2008-08-17T14:20:42.137 回答
2

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.

于 2008-08-17T15:05:51.170 回答
0

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.

于 2008-08-17T14:57:13.823 回答
0

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.

于 2008-08-18T05:55:19.380 回答