Disclaimer
I know very little of compiler and interpreter theory and have never (yet) created a working implementation of a compiler or interpreter. What you’re about to read or (most likely) skip over is a Head-in-Ass post and feel free to flame me on parts where I’m wrong, which will be most places. Do realize that this is one end user’s opinion of the matter and any perceived insult upon any author(s) is not intended and please do not take it as such.
I sincerely apologize for my limited knowledge and lack of understanding and practice, then ranting about something I know very little about.
Run-time Classes
It is my understanding that anything that is compiled is faster than something that isn’t. Correct? Why then do Functions in PHP get preferred compiled treatment over Classes? Do the authors hate classes and people that use them? No, it is a guess, but I highly doubt it.
From my reading and the little bit of research I have done on the matter, it is extremely hard to feature classes in any language. In PHP 4, they were little more than array’s with function scope. Pretty easy, just name and value pairs with pointers to function calls when used. PHP 5 is more feature packed with visibility, interfaces, and iterators.
However, Classes should still be compiled before they are used and not at the run-time. If Java can do it, I’m pretty sure PHP can. I’m sure they have some good reason as to why they wait until run time, but if it is because they are unsure as to which class will be used, then checking the code before hand might help. Other then that, I’m lost and would accept the answer. Still doesn’t sound right.
Class Optimization
Class or object Optimization is a black art that even C++ has trouble with and I only know of Java that succeeds in doing it well. Why is it then that Java can succeed in optimizing objects, so that they can compete at the level of C++ (using the special intepreter)?
My (un)educated guess is that it was built from the ground on up for objects and they can compile object code to that of variable and function level. Also, they can use special bytecode to represent core library code, speeding code up even more.
The advanced, current generation C++ compilers has the intelligence to read poorly written code and optimize it in the assembly to where it is quicker than what it would have been. I believe similiar techniques that Java and C/C++ uses can be applied to PHP. I’m no master, but intelligent people created the Zend Engine, so I’m sure they’ll be able to think of something. Some of these techniques might already be applied in the Zend Optimizer, but I believe they should also be moved to the core, if at all possible.
All I Really Want
Is to write an algorithm from N3/2 to 2N without getting my ass kicked. Hell, even passing PHP N lg N algorithm with a lot of data will rape you big time. Some would question the merits of the first algorithm usage as you really shouldn’t use them in any language, let alone one that is interpreted. That and some would state that if you are in need of such an algorithm, it is best to set if off on the side in a Cron Job.
To them I say, “Yeah, but I should if I so desired.” I did use a cron job for such a time consuming algorithm task and it took a long time. Even after I optimized it and cut some wasteful, useless cycles. Probably could have optimized it some more come to think of it. Reminds me of a post I read about someone optimizing another’s code project… anyway, enough of that.
If you can’t display a page within 0.2 or below seconds, then the user will feel as if they are on dialup. Even complex SQL queries with a lot of loops can bring an application to its knees, which again could seriously be optimized by using cronjobs and cached files with finished information.
The point I’m trying to make is that I shouldn’t have to worry about a set limit of SQL transactions, how complex the transactions are, and how many loops I have on any given page. I shouldn’t worry that caching is a ‘best practice’. What, am I using? Perl?
“You don’t want more than 200 lines in any given Perl script…” says the teacher as the students, half listening while downloading porn, agrees, “…1000 lines is really the max.”
So, what? Do you tell people you don’t want any more than 10 database transactions and want to iterate no more than 200 elements? Makes sense, but what if I have an extremely advanced task that I want to do in PHP and wish to use classes to accomplish it? Nope sorry, you need to use another language. Damn! I love PHP.
Namespaces
I was satisfied with the explaination as to why namespaces were removed from PHP 5, so I just forgot that they were ever there. The choice as to fix something that wasn’t “broken” and delay PHP 5′s release or strip the wishlist feature completely out. I would have chosen the same.
However, I believe namespaces could still be revisited for PHP 6 and if not, then definitely PHP 7. My hopes are on PHP 7, PHP 6 with Unicode support does look really sexy. Mmm, TextIterator. SPL continues to add awesome and sweet classes and interfaces, so continued development of that is also something to look forward to.
Can’t Use Same Symbol For Two Different Things
I can’t understand that in other languages, one symbol can be used for 2 or more different tasks, but in PHP using ‘:’ for namespaces breaks the ternary operation. Also, you wouldn’t be able to use ‘:::’, because it would read as either ternary->class reference or class reference->ternary. But they can use ‘?:’ to mean ‘is set or’, which is for setting default values when the variable isn’t already set.
I think that if they set their minds to it and really wanted to support Namespaces, they could have made it work.
PHPc
If interpreting PHP is causing so much trouble for implementing new features such as import and namespaces, I think they should just take the byte code, compile classes also, and compile to a file for later. Use the ‘phpc’ extension to reference that it is the compiled file. Kind of like ‘phps’ is for displaying source with pretty colors.
They can do it like Java, interpret the PHP byte code instead. It would make it quicker, allow them to do extra checks for symbol tables, allowing for namespaces among a much happier user base. I wouldn’t expect it for PHP 6, but PHP 7 would be a good candidate, what else can you put in PHP 7? Might as well try for the kitchen sink.
Now Insert Foot In Mouth Like So
The Zend Engine authors are gods in their own rights to make PHP as quick as it is currently. I want more, “Feed Me, Zend!”
I have trouble even following how to make an extension. For me to try to mess with the Zend Engine is like trying to create and throw fire from my hands. Not going to happen.
I can only humbly (not so much any more) request that these features are added in a timely matter. I kind of invested to much time to just go to another language. Java Servlets, come on! In my experience, a virtualized web snail moves faster than the most simple Servlet pages out there. More of Tomcats fault, I think, need some Mod_Java up in here.
Ruby on Rails does look enticing, but I’m still put off by Python. I figure I’ll probably break down and learn one or the other eventually anyway.
While I’m On a Roll
For SPL, if they can maybe add in MVC interfaces or abstract classes for managing that. It would be cool for say PHP 7 or if they can get it in PHP 6. I mean, adding in some part the Zend Framework as C code counterparts would be cool for the final version of the thing. To make it fair, adding support for eZ Components also would be sweet.
It would be nice if PHP had a comprehensive Security Framework that secured not only the input (using the awesome Filter extension), but also output for XSS attacks and automatic Session security with allowing the user to work with the automated security for work arounds. The HTML filters should also work with attributes and checks for Javascript code.
A sandbox so that the coder doesn’t end up raping the system. I believe safe mode was meant to do this, a better one perhaps for functionality like shell commands.
A way to tell if a bot is accessing the page and ways to either work around the bot or deny access to it. Kind of like Bad Behavior except in core extension form.
I would love to say that I use PHP because it is secure, quick, and saves me time coding. I can say two some of the time and 1 most of the time, but not all three any of the time. Interpret this any way you wish.
PS
Even if it is possible to get my address. Please don’t hunt me down, crave code all over my body, and then set me on fire. That would totally hurt and I really don’t like pain.
Possibly Related Posts:
- Bullet: E-Book Library Management and Content Server
- Using ZendFramework 2 beta1 For Directory Project
- The Way of Kings and Cosmere Theory
- “In Time” Movie Premise Flawed
- Completing HTTP Library For PHP
PHP doesn’t try very hard to optimize because it’s going to tear everything down again at request shutdown. For the average script, the cost of optimization outweighs the benefits received over that one run of the script.
Maybe we could use a pragma. ‘declare optimization=PHP_OPT_LARGE’ or so. But then you’d need people to debug and maintain the optimizer.
Good read indeed.
Php does have it’s ups and downs but then again what program doesn’t?
also the idea of php compiler is already out there, its only in a form on a framework or template. For example Smarty is a really good template engine that “compiles ” your code to save web browser from accessing database on every click.
@amedjones
No, not really. What it does is convert the smart tags to PHP tags, it has nothing to do with optimizing Database connections. It uses caching to save from accessing the database on every page load. The issue of the Smarty caching is that you have to decide how you want to split the pages out, so that some areas can be reloaded with database or other dynamic data.
What I would have liked is if Smarty or PHP compiled and saved pages using the PHP byte code to further save from parsing and compiling. Just like how Smarty saves a parsed page converted to PHP to save from parsing the smarty tags on each page loading, it would save a lot of time if PHP also saved the parsed, byte code page.
If PHP was compiled, then it could make the decision itself on how many times the database needs to be accessed and when data in the database changed. You can create a framework yourself for when database data becomes “dirty” and the page needs to be recached, but you would need to use an outside means, like Sessions, a file, or a database table.