Press "Enter" to skip to content

How to Contribute Code to PHP

PHP migrated its source code to git earlier, and also made a mirror on github (https://github.com/php/php-src). This has made it easier for more developers to contribute code to PHP.
I'm writing this article today to serve as a walkthrough for friends in China — those who are willing to contribute to the PHP open-source community — on how to contribute your wisdom to PHP.
Now, suppose you want to contribute a new feature. In that case, besides doing the following steps, you also need to submit an RFC on wiki.php.net. I'll cover that later. For now, let's keep it simple: suppose you just want to fix a bug in PHP (generally, you can find already-reported PHP bugs here: PHP Bugs). Now suppose you've already figured out how to fix this bug.
1. First, you need a github account. If you don't have one, register here: Register on github.
2. Fork PHP's source code. On the top-right corner of the PHP Github page there's a fork button. Click it.
3. After forking, you have your own PHP source-code repository. Now you can modify PHP's source code in this repository to fix the bug.
There's not much to say about the actual development, but if you have questions about using Git, you can refer to a Git manual, such as this one: ProGit
Here I'll provide a simple explanation for everyone. If you're starting development on Github, on your own PHP repository's page there will be a note, for example on my PHP repository page https://github.com/laruence/php-src:

ssh  git@github.com:laruence/php-src.git

Then, I'd run this on my local development environment:

$git clone git@github.com:laruence/php-src.git

Then, you get a php-src directory. Go in and start developing, 🙂
4. Once you've finished your fix, you commit it to your own PHP repository. Then, on the top-right corner of your PHP source repository's Github page, there will be a pull request button. Click it.
When submitting, please pay attention to the format of your commit message. First, the first line should be a short description (at most 79 characters) explaining what change you made. If one sentence isn't enough, insert a blank line and then type the long description (see New Commit Message Format):

<max 79 characters short description>\n
\n
<long description, 79 chars per line>
\n

If you're fixing a bug listed on bugs.php.net, then your short description should be in a format like this:

Fixed Bug #bug_number (description of the bug)

5. Then, fill in the relevant information, and Github will send a Pull Request email, containing your update, to PHP's pull-request mailing list. (Don't worry about your English — as long as you can express it, we can understand it. Of course, if you really don't want to write in English, that's fine too — write in Chinese. When I see it I'll handle it; whatever I can't handle, I'll also translate for you.)
6. Finally, if PHP's Committers think your fix is correct (there are a few options to note when contributing code to PHP — I've left those below), they will Merge your Pull Request into PHP's source code.
Now, suppose what you're submitting is an update (adding a new function, adding new syntax). Then at the same time you submit the Pull Request, you also need to send an email to the internals@lists.php.net mailing list to explain why you're submitting this update, so that the people on that mailing list can discuss it together and help you refine your idea.
Appendix:
There are a few things to note when contributing source code to PHP (common issues):
1. Only write C89-compatible code. For example, don't use single-line comments (//), and variable definitions must all come before any statements (at the start of the block)..
2. Variable naming: follow PHP's existing conventions, don't use camelCase.
3. For some very small updates, such as a typo in the code, I still encourage everyone to submit a Patch on bugs.php.net, since merging a Pull Request can sometimes be a bit of a hassle.
For more PHP code conventions, see here: Coding Standards
For more on how to submit a patch, see here: Submitting patch

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.