-2

I am looking to convert my PHP library code as a PHP extension. The full library is under a namespace. There are many PHP classes I am using under my library.

Is there any tool which convert the PHP code to .so and .dll PHP extension (with the namespace usage) ?

Writing the code in C or CPP is too much of work.

Code Help
  • 72
  • 1
  • 6
  • 1
    Well as far as I know the C route is the only way. – RiggsFolly Sep 02 '15 at 07:58
  • 1
    There is no tool that will automagically convert PHP code to a PHP Extension, but tools like [Zephir](https://github.com/phalcon/zephir/) provide a half-way DSL that can easily be converted from straight PHP and then compiled against Zephir to build a PHP extension.... I'm actually showing how to do exactly that in a tutorial at the PHPNW conference next month – Mark Baker Sep 02 '15 at 07:59
  • Can I use the namespace also with Zephir ? – Code Help Sep 02 '15 at 08:02
  • 1
    Yes you use namespacing with Zephir, take a look at the [docs](http://zephir-lang.com/) to see what it does – Mark Baker Sep 02 '15 at 08:06
  • Thanks. Post your comment as an answer. – Code Help Sep 02 '15 at 08:10

1 Answers1

1

There is no tool that will automagically convert PHP code to a PHP Extension, but tools like Zephir provide a half-way DSL that can easily be converted from straight PHP and then compiled against Zephir to build a PHP extension... and yes, it does work with namespaces

The Zephir docs are pretty good, and give a decent explanation of how to write code for the Zephir DSL, and there are blog posts like marmelab's that show how to convert a PHP (namespaced) class to an extension using Zephir.

Edit

Since posting this answer, I've also discovered PHP-to-Zephir which claims to be able to convert PHP code to the Zephir DSL, although I haven't tested it in any way

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • Thanks for your answer. Zephir is the tool which I am looking for and I successfully managed to convert my classes to the PHP extension with the help of this tool. – Code Help Sep 03 '15 at 06:40
  • I managed to change my PHP code to extension with both PHP-to-Zephir and Zephir. – Code Help Sep 06 '15 at 14:19