Page 1 of 1

The Future of PHP

Posted: Sat Nov 25, 2006 10:55 am
by supermike
I think there are three, fairly fixable things in PHP that many PHP developers would love to see fixed in a future version of the language. If you all know where I can contribute my view to the actual PHP language developers, please let me know.

* Namespace support, and how it's implemented:

XML.Document.Parse()?
XML::Document->Parse()?
XML::Document::Parse()?
XML->Document->Parse()?
XML-Document-Parse()?

oDoc = XML->Document;
oDoc->Parse(); ?


* Consistency in the order of parameters on functions, such as using an ordering strategy like Source/Target + most significant and largest byte-value parameters all the way down to least significant and least byte-value parameters. Some of the string functions in place today still cause me to grab my manual because the parameter order is inconsistent.


* Keeping the global namespace functions in place for two major releases (with a php.ini option to eliminate them if you want, speeding everything up) before they are deprecated forever. The ideal thing would be to use the new namespace system.

Posted: Sat Nov 25, 2006 4:59 pm
by Ambush Commander
Sounds like you want to use Java.

Posted: Sat Nov 25, 2006 7:52 pm
by supermike
Ambush Commander wrote:Sounds like you want to use Java.
Actually, no. I love PHP. I just think that namespaces make sense and keep things organized. I'm not a fan of many things in Java. Here's some things I dislike very much about Java:

* Strict typing. How many of you tried Java and left it because this drove you crazy? This especially comes into play when using the Swing API, for instance. So you find that widget you need, and want to feed it some data, but then you find it only requires a certain type of data type. Fine, so how do you get that data type? You may have to jump through two or three more functions with that data just to coerce the right kind of data type to feed to the API you found in the first place. That's aggravating and slows things way, way down.

* The community. It's filled with OOP academic types who don't want to get anything done and would rather sit in meetings way, way too long, perhaps for as long as a month, working out the purity of their design pattern and APIs before they even right a lick of code. Sounds nice and all, but managers want results. With PHP, I can have my OOP with a couple morning coffees, be done with it, and move on.

* The MVC model. This is very convoluted. You'll see what I mean when you try to write a Java Swing project that collects a query on a form, hits the database, and tries to print nice reports. The MVC model to me, when I did that, was very strange. I couldn't think in this mode. It was like trying to put a large square peg in a small round hole. I thought if I had done it in VB or C#, I would have been done by then. That's before I discovered PHP.

* Having to compile. I hated having to compile, and the compiler was very picky where all the files were. Making jars was an aggravating process for me when I just wanted to make code changes and be done with it. With PHP, I had none of these problems.

* Everything is an object. This made reading the code confusing and also slowed things down. It's hard to believe that Java slightly beats PHP in some kinds of time tests, although that's what I think I see now. I don't know how they do it because for awhile there, PHP was faster. I just can't fathom how the "everything is an object" philosophy in language design can speed up the language.

* funkyVariableNames. Pleeeze. That's just silly and illogical. Instead of what the Java purists wanted, I like to stick with variable names like:

$nNumber
$sString
$dDate
$bBoolean
$cChar
$oObject
$hHandle
$asArrayOfString
$anArrayOfNumber
$xsByRefString (returns an updated value -- x means "xfer" or "transfer")

...And I like my function names like GetAnswer().

I'm "old school". Sorry.

* Missing libraries. I sure do have trouble in PHP when I try to run something but I'm missing a library, but it happens a heck of a lot more in Java. This was also the case of some really crazy sounding errors.

* Deprecated APIs. I got sick of writing my Java projects for 6 months, only to find it reviewed by peers saying, "Um, dude, you can't use foo() -- it's been deprecated (or is planned to be deprecated next year)." PHP has far, far less of this.

* APIs not working on certain versions of Java. Unlike PHP, where there's really only one good engine out there, Java has splintered into many versions. I got sick of sending my code to someone and then they said, "I can't run your stuff on my version of Java." And it was either the version or the vendor of Java that was the culprit. Augh!!!


So, let's get this out of the way, I adore PHP. I just think that every once in a millennium, some language designer introduces a feature that even old schoolers like me think is cool, and namespaces is one of them.


I've been doing some reading on the web, and it looks like the only discussions going on right now are to use a namespace you can implement easily in PHP4, 5, 6, and beyond. It just uses static methods and properties to simulate it. If you're careful and use a "property bag" concept in your static methods, you can create something similar to how namespace objects work. It looks sort of like:

$sResult = XML::Document::Parse(blah blah blah);

and

$sResult = Server::Property('HTTP_REFERER');

And then it's up to Zend and/or the top level community guys to create a set of libraries that use this new namespace system, and which introduce GCC C/C++ PHP extension modules to carry out the tasks.

However, this could suffer a speed hit. The faster technique, in my opinion, would be to permit normal namespace separators like "." and require that strings be concatenated with <space>.<space>. That way, the interpreter could still run fast even though "." is used as a namespace separator for something like:

$sResult = XML.Document.Parse(blah blah blah);

and

$sResult = Server.Property('HTTP_REFERER');

Posted: Sat Nov 25, 2006 9:08 pm
by Ambush Commander
I was being somewhat facetious (as all of the features you requested were already implemented in Java), but I agree with most of your objections. Removing all globally name-spaced functions was what made me raise an eyebrow (even if you phased them out over two major versions).

There's a bit of prior discussion about namespaces already on the web, keep googling! Changing parameter order breaks backwards compatibility and is unlikely to happen.

Posted: Sat Nov 25, 2006 10:22 pm
by supermike
Ambush Commander - On facetious....Ah, I see. No problem. I'm easy to get along with. :)

On changing parameter order. Here's where I think we can all still get along. The new API can have the fixed parameter order, and we can keep the old API with all its "duh moments" in the global namespace (unless you disable it in the php.ini to speed up PHP interpretation). We can keep it through two major releases, and by major I mean the "a" in a release like "a.b" (so, for instance, PHP 7 and PHP 8). Then, after two major releases, we can cut the cord on the old API and stick with the new namespaces, which are cleaner and more consistent with a parameter order that could almost be guessed, which I think should look like:

function Foo(<primary source data>, <list of largest byte and/or most significant variables, sorted in order of usefulness to the API>, <list of smallest byte and/or least significant variables, sorted in order of usefulness to the API>)

...for instance, here's a made-up function to insert text before certain items of text (rather than replacing it):

function InsertStrings(&$sHaystackText, &$asNeedles, &$asItems, $bUnicodeSensitive, $bCaseSensitive)

...which I think has a more logical parameter order than:

function InsertString(&$asNeedles, &$asItems, &$sHaystackText, $bUnicodeSensitive, $bCaseSensitive)

I'm sure you can think of a few string functions where having this almost guessable parameter order would make a lot of sense. And whoever does the new String namespace, they consider the parameter order of the rest of the functions in that namespace, as well as the parameter order of the rest of the functions in other namespaces, so that everything is consistent.

Posted: Sun Nov 26, 2006 10:34 am
by Christopher
supermike, these suggestions have been made before many times. The whole library/parameter think comes up from people who move from other languages (especially Java) to PHP. It dies pretty quickly usually once they start using PHP because it ends up that the naming doesn't really bother PHP programmers that much. As for the parameter order, again I recall they did a survey of the functions and there really are only a couple that are different -- again most PHP programmers don't really mind. And if you are familiar with the original library for a supported sub-system then you will like PHP because it usually follows that naming -- often a plus.

Namespacing comes up again and again. From my pont of view you really have to want to program PHP is a way that is not like PHP if you require namespaces. They may be handy in some cases, but are not really much better than PEAR naming in reality (which probably drives guys like you nuts ;)). Worst of all, when PHP gets namespaces they will be different than other languages and not exactly what you expect due to the reality of the language. You should read the discussions on the internals list to learn more about the issues.

It's not that the suggestion are bad per se ... it is just that they (to me) show a lack of understanding on how PHP is used to solve problems, which is different than other languages. Not that PHP could not use improvement -- all lanugages can. But, if you don't really want to use PHP as PHP, then there are a multitude of other wonderful languages to choose from that might work for you better. I get the impression that (unlike some other languages) PHPers don't think their language is the best -- they just think it is good at building web applications using a certain development style -- and that works for them.

Posted: Tue Nov 28, 2006 1:54 am
by alvinphp
I disagree with a number of your views on Java. You do not have to use Swing, MVC is quite clear and easy to understand in Java (using JSP/Servlets/JSTL and either POJOs/JBs/EJBs), I like strict typing (call me crazy), I love objects, and compiling is a second thought if you use any half-decent ide.

The one thing I do completely agree with you on is the community. Java seems to have very little community spirit for those trying to learn.

Posted: Tue Nov 28, 2006 3:51 am
by Jenk
Everything but the community, that you have listed, is why I like Java :\

The community sucks because Java is the bread and butter of many University Courses, thus the 'experienced' are either a) People fresh out of/in to college and want to rewrite the book b) Fresh out of/in to college and have the "I had to go to Uni to learn, so should you" attitude c) 'Old school' and despise Uni students that fit into a or b, and assume all learners to be so.

The rest of us are left in hanging in the balance.

The best way to learn Java, in my humble opinion, is learn within a language that has a good community, such as PHP, then apply what you have learnt to Java.