DEV Community

Cover image for PHP Functions for Golang - phpfuncs
Serkan Algur
Serkan Algur

Posted on

PHP Functions for Golang - phpfuncs

Hello, Serkan is here.

This is my second post in the DEV community. Currently, I am making monthly earnings with websites developed with PHP and Python. But I am sympathetic to Golang. And I'd created a module for Go :)

Why I created this module?

GitHub logo serkanalgur / phpfuncs

PHP functions implementation to Golang. This package is for the Go beginners who have developed PHP code before. You can use PHP like functions in your app, module etc. when you add this module to your project.

While trying to learn Go, I realized that I was not able to reach the speed I used to be. I think this was due to the fact that I could not break the habit of coding with PHP for about 15 years.

After realizing this, I asked myself if I could write a module that could speed the transition from PHP to Go for both myself and beginners. So I could have speed up my learning process.

This is the starting spark of phpfuncs module :)

The module is 4 days old and I chose the MIT license. I rebuilt some PHP code with Go. During naming, I tried to use the same patterns as possible. For now, there are 93 functions (math, file system and general functions), 2 types and one constant depending on these functions.

You can check all functions on modules page.

I take care to use the explanations and definitions available on I want to complete this module as fast as I can and provide convenience to software developers like me who switch from PHP.

You can also review and contribute to the module if you wish. I add an example of reading a file below. We can do this in the same way as we do with PHP (I haven't added the file writing function to the module yet).


go get
Enter fullscreen mode Exit fullscreen mode

File Read Example

As you can see in the example below, the plugin allows someone who has used PHP to use almost the same function structure in a very simple way.

Note: This example not suitable for Go Playground.

I organized the function names with underscores according to Go. I created some normal function names differently in order to avoid possible errors. For example, the name fread() should normally be Fread() but I created it as FRead().

I hope I can help developers with this module.

Thank you for your reading.

Top comments (2)

yoursunny profile image
Junxiao Shi

My favorites are missing:

  • phpinfo
  • file_get_contents

Also, PHP's fopen can handle HTTP URLs. The second parameter should be a string, not numeric constants.

serkanalgur profile image
Serkan Algur

Thank you for your comment 😊. These two functions have on my list already. I can improve FOpen function.