php to python code converter

kay at fiber-space.de kay at fiber-space.de
Sun May 10 14:05:49 EDT 2009


On 8 Mai, 17:19, Pascal Chambon <chambon.pas... at gmail.com> wrote:
> Hello
>
> That's funny, I was precisely thinking about a php to python converter,
> some weeks ago.
> Such a tool, allowing for example to convert some CMS like Drupal to
> python, would be a killer app, when we consider the amount of php code
> available.
>
> But of course, there are lots of issues that'd have to be fixed :
> - translating the php syntax to python syntax
> - forcing scope limitations where php doesn't have any
> - handling differences in semantics (for example, the booleanness of "0"
> or)
> - handling the automatic variable creation and coertion that php features
> - handling the php types like arrays (which are neither python lists nor
> python dicts)
> - providing a whole mirror of the php stdlib (string and file functions,
> access to environment vars...)

Some thoughts.

1) Syntax. Not a big deal.

2) Semantics. My favourite approach was to create a Python framework
that represents PHP in Python and enables round-trips. So one could
translate forth and back. Python code that is compliant to the
conventions of the framework can also be translated to PHP and for
each PHP program P following equation holds:

   py2php(php2py(P)) = P

This makes readable code mandatory.

3) PHP stdlib via C bindings ( ctypes? )

4) Corner cases of bindings: cut them off. Not everything has to be
translated. But produce stubs that raise NotImplementedError
exceptions.

Same arguments apply to Javascript. Not sure about Ruby but I do think
a parser is feasible despite context sensitivities. Ruby is not my
concern though.

Personally I'd be interested in Wordpress which I like and use.

Kay



More information about the Python-list mailing list