Viewed   261 times

I have a business logic classes that are written in pure C# (without any specific things from this language) and I would convert this code into PHP. I can write my own parser, but think if I could someone did it before me.

Could you please tell me where can I find this kind of converter?

Ps. As I've written I use only plain C# programming in this language. Only arguments, declarations of variables, equations and control statements.



I know you're hoping for someone who had experience but in case no one comes forward...

You might consider just copy and pasting the code into a PHP script and checking what breaks. Write a parser to fix that, run it across the entire script, and see what's the next thing that breaks. Continue until the script functions as expected.

If you're not using any of the more involved .Net classes I can't imagine you'll have too much trouble.

Monday, August 29, 2022

You actually should ensure that you type what you mean:

$bigint = 9999999999999999999;

Is not a PHP integer but float:


If you would have done

$bigint = (int) 9999999999999999999;

You would have set an integer in fact, but it would not be the number you might have expected:


It's no problem at all to turn that into string as you might have guessed. So take care when you write numbers into code that you actually write what you mean.

See this line again:

$bigint = 9999999999999999999;

try to understand what you have actually written. It's not an integer at all because PHP will turn it into a float. See Example #4 Integer overflow on a 64-bit system in the integer manual page.

If you need higher precision, checkout GNU Multiple Precision, it might have what you're looking for. However, this won't change how to write numbers in PHP:

$bigint = gmp_init("9999999999999999999");
$bigint_string = gmp_strval($bigint);
var_dump($bigint, $bigint_string);


resource(4) of type (GMP integer)
string(19) "9999999999999999999"
Sunday, November 20, 2022


Okay, after checking out this thread, I've decided on this approach as the only one that seems to return an accurate measure:

$dt = DateTime::createFromFormat('Y-m-dTH:i:s.uZ', $date);
$now = new DateTime();
echo ($now->getTimestamp() - $dt->getTimestamp())."n";


In PHP 5.3 using classes (no 'U' format):

$dt = DateTime::createFromFormat('Y-m-dTH:i:s.uZ', $arr['launchTime']);
echo (new DateTime())->format('U');

In PHP 5.3 using procedural calls (also works like final solution):

$dt = date_create_from_format('Y-m-dTH:i:s.uZ', $arr['launchTime']);
$now = date_create();
echo ($now->getTimestamp() - $dt->getTimestamp());

In any version using strtotime (return wrong time):

echo time() - strtotime($arr['launchTime']);
Tuesday, October 25, 2022

Did you even try to implement that yourself or read at

Write those lines before the first output of the file.
Should do the job (although untested):

// ...
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: origin, x-requested-with, content-type');
header('Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS');
Monday, October 10, 2022

Actually include and require are identical in all except require will fail with E_ERROR while include will issue a warning. Also both of the statements are only activated when they actually executed inside script. So the following code will always work:

echo "Hello world";
if (0) require "non_existing.php";

The answer to your question is that index.php will be parsed first and executed. Then when include "init.php" encountered the file init.php is parsed and executed within current scope. The same for layout/header.php - it will be parsed first.

As already noted init.php will be parsed and executed each time include / require is called, so you probably will want to use include_once or require_once.

Friday, October 21, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :