0

I know php code can be rewritten in C. So just like a strpos() function, I want to add my own built-in function (lets assume a function name vinod) in php source code. Is this possible? If yes then let me know the procedure.

Sample function pseudo-code: my function will return str in a heading tag1.

vinod($str)
{
    return <h1>$str</h1>;
}
Jk1
  • 11,233
  • 9
  • 54
  • 64
  • 1
    Why do you want to extend the PHP parser? Just write you own functions in PHP... – Uwe Allner Apr 17 '15 at 07:10
  • Just why? 1. You would need to write your code in C 2. You would need to re-compile the source code and it would be a HUGE amount of work to add/update all entries in the source code that your function works! Then you can also write your own program language... – Rizier123 Apr 17 '15 at 07:12
  • 1
    https://github.com/php/php-src – Reuben L. Apr 17 '15 at 07:15
  • Sara's book is a bit out of date now, but it's still the definitive guide to editing the PHP core - http://www.amazon.com/Extending-Embedding-PHP-Sara-Golemon/dp/067232704X – Mark Baker Apr 17 '15 at 07:16
  • @VinodJakhar ^ Seems like that's your job. How should you be able to do your job if we have to code for you? – Rizier123 Apr 17 '15 at 07:20
  • 2
    @Rizier123, friend I just wants some help. I am not asking you to do my job. – Vinod Jakhar Apr 17 '15 at 07:28

1 Answers1

3

You can make a PHP C extension, to add your custom C functions to be available as PHP native functions see below:

  1. Why write your own extension?
  2. How do I build my first PHP extension in C
  3. Writing PHP C extensions
  4. A C++ library for developing PHP extensions
Community
  • 1
  • 1
Nikos M.
  • 8,033
  • 4
  • 36
  • 43