Cover photo for post My first patch to PHP

My first patch to PHP

Hehe, some might say, that those 10 lines of C code are not even worth calling it a patch. Especially, since it was mostly copy and paste work and since Christian Schneider also adviced me for some improvement. Anyway, Marcus just commited my enhancement to pathinfo(), which adds a new field "filename" to the returned array of path elements.

Originally pathinfo returns the parts "basename" (the complete file name), "dirname" the directory the file is located in and "extension", the filename extension. In some recent projects I often needed the filename wihout the file extension, too. I tent to extract it manually (either by first using pathinfo() and the basename() again with the extracted file extension, or by doing it manually using strpos() and friends). After doing so for about the 10th time I decided to dig into the C source and prepare a patch for adding the "filename" key to pathinfo()s array, which contains the file name without the file extension.

Coding C is somewhat strange. I never really dealt with it (also I read a book about it), because the only purpose where I can imagine to use it, is coding a PHP extension. Dealing with pointers is an interessting way of coding, also it's kinda hard, if you are not used to it. So 2 hours later my first patch against the 5_2 branch was ready. Infact it was easier than I thought, if you know where to find the right places in PHPs sources.

Anyway, tiny or not, my first patch to PHP is commited and will be part of PHP 5.2. :)