Hello guys, I wanna know how to extend PHP functionality beyond frameworks, functions or classes libraries ?
An example about what I am trying to achieve is to be able to create my own operators, make language constructs myself (like foreach, while .. etc).
Also there are a lot of built in functions, they are just available globally not in packages or something, so I have a whole range of reserved keywords that clashes with whatever classes or functions I am trying to write.
I know an ideal solution would be "go and program in some other language other than PHP". This is logical and I know python & ruby already, but I wanna make use of the popularity & availability of PHP on a vast majority of systems.
I was thinking of creating a tool to compile some custom language i make myself with all the freedom i am seeking to valid PHP code but if I know how to do that i would better hack PHP core but I don't know much c or c++ (may be only how to make a tic, tac toe)
So how can I acheive that ? if it's not possible from PHP itself can I write extensions/alter the function of php using python or ruby ? if this is not possible either what are the things/languages I need to learn to get to what I am trying to do ?
views:
59answers:
3If you need, or think PHP needs new functionality in PHP you can:
- Suggest it to the PHP / Zend / Pear Community
or:
Use another language
(PHP can easily work with other languages.)
An example about what I am trying to achieve is to be able to create my own operators, make language constructs myself (like foreach, while .. etc).
You can't, and shouldn't. That isn't supported by the language. Even if you download the PHP source code and add your own custom operators/keywords, they aren't going to be magically available on other PHP installations. Since you said the only reason you want to use PHP is because of it's popularity and availability, this kind of defeats the purpose.
I was thinking of creating a tool to compile some custom language i make myself ... to valid PHP
Compiling one scripting language into another scripting language is a bad idea. You're going to be writing the most unportable code imaginable.
...but if I know how to do that i would better hack PHP core but I don't know much c or c++ (may be only how to make a tic, tac toe)
If you don't know any compiled languages, you shouldn't even be considering writing a compiler for your PHP-drived language.
if it's not possible from PHP itself ... what are the things/languages I need to learn to get to what I am trying to do ?
C, obviously. Learn the language that PHP is developed in if you intend to change core functionality.
What is the goal of trying to create an other language(custom), that no one know how to use. Go with PHP as is, and build extensions in C. Than you can propably name you internal extension function as you want.