tags:

views:

59

answers:

3

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 ?

A: 

If 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.)

Enrico Pallazzo
I already said that i know other languages but I have a good reason to think of extending/improving PHP. I think it worth trying that myself and when i get to anything useful i can suggest it.
Lettuce
+2  A: 

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.

meagar
Lettuce
@Lettuce Adding a compile step with a parser that makes heavy use of regular expressions is going to turn everybody away. If you think your ideas really are good, suggest them to the PHP team.
meagar
I am not able to try these ideas out to know if they are good, due to the limitations of the language that made the only chance to create a new functionality is to write functions or add classes.
Lettuce
+1 for the "custom extensions defeat portability" point.
deceze
A: 

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.

The goal is to make the things that are not possible now to be possible. Imagine if PHP was all object oriented and datatypes were just objects ! Imagine if all the functions with inconsistent naming conventions were just wrapped in classes/packages or whatever and let me choose whatever names i like for my functions and classes !
Lettuce
@Lettuce Imagine using Ruby. Turning PHP into something not PHP is a pointless exercise.
meagar
Ruby is cool but PHP is so popular that customers who don't know how to use a mouse ask to get PHP sites !
Lettuce
@Lettuce Then give them PHP sites, not sites in some language that compiles to working-but-unreadable PHP.
deceze