Building your first C extension for PHP

Marcos Marcolin • December 26, 2023 • 2 min read

php phpfoundation opensource c

I've previously covered the importance of determination when facing challenges in programming. If you're interested, the link is available at the end of this post, to avoid distractions.

Last month of the previous year, I had the chance to give a talk about developing C extensions for PHP. The main goal was to share knowledge, which in turn helped me improve my own skills in this specific area.

This talk was first given to a smaller audience at PHP Conference 2023, as mentioned earlier. Later, I gave it to a wider audience of around 40 people at IXCSoft, the place where the talk originated.

I was extremely happy to be able to share this content and demystify, at least in part, a complex subject that's often lacking in information.

Below, you can check out more technical details about the content presented.

Developing your first C extension for PHP

During the talk, I highlighted a few points for creating PHP extensions, making use of Zend Engine features that make the development process easier. 🐘

As an example, I demonstrated creating a C extension that exposes a base64_validate() function in userland (PHP). I also explored the object-oriented approach by creating a class.

The code's stub ended up looking like this:

<?php

function base64_validate(string $str = ''): bool {}

class PHPConfBR
{
    public function base64_validate(string $str = ''): bool {}
}

The main topics covered in the talk include:

Among other topics covered briefly.

The talk's slides are available on SpeakerDeck.

The full example is in my repository on GitHub.

To everyone who attended, thank you very much for your support. 🤝


Article mentioned at the beginning of this post: Be determined to solve challenging problems in Programming .


I hope you enjoy the read, and if you have any questions or comments, feel free to share them.

Share: