Jump to content

PHP 6(or 5.5) Wishlist


Hall of Famer

Recommended Posts

Well it seems that the development of PHP6 has been delayed over and over again. I am not sure of the details, but seems that they are planning something big for PHP 6. Here's my wishlist for PHP6, and theres a chance some of them will be implemented in PHP 5.5.

 

1. Fully Object-Oriented script:

PHP is not a fully object-oriented language, which I think everyone agrees here. In programming languages such as Ruby, everything is an object. And moreover, a perfect script requires everything to be an object, thus no procedural programming at all. Unfortunately PHP is not yet a complete programming language, it has lots of non-object elements such as number, string, array and session. Although it is not impossible to create user-defined classes for string and session, their usefulness is severely limited and can be quite resource-intensive. If PHP optimizes object-oriented number, string and session, such problems will surely go away.

 

So the idea is that, everything is an object! And moreover, for numbers, strings and arrays it is unnecessary to use the new keyword to instantiate an object(though this choice should be available). Old syntax still works, and the variable is automatically converted into objects. For instance, a string may be defined with single or double quote only(with the new keyword and parenthesis omitted), but it instantly becomes an object that can access member methods such as string::toupper() and string::crypt().

 

 

Here is a sample of proposed code for PHP6's fully object-oriented code: String

<?php
//PHP5: 
$str = "This is a String";
$upper_str = strtoupper($str);
echo $upper_str;

//PHP6: 
$str = "This is a String"; 
//or:
$str = new String("This is a String");
$system->output($str->toupper());
?>

 

Here is another example for Array(although ArrayObject extension kinda works already, its tedious to use...)

<?php
//PHP5: 
$arr = array(New York", "Newark", "Philadelphia", "Washington", "Boston");
$sort_arr = sort($arr);
print_r($sort_arr);

//PHP6: Both syntax should work
$arr = ["New York", "Newark", "Philadelphia", "Washington", "Boston"]; 
//or:
$arr = new Array("New York", "Newark", "Philadelphia", "Washington", "Boston");
$system->output($arr->sort());
?>

 

So yeah, everything is an object. Every statement is carried out with either a new keyword, a single arrow -> operator or a resolution scope operator ::. I know even this does not guarantee good object-oriented design, you can easily mess up your script by writing a long lines of code that are basically no different from amateur procedural programming at all. The true greatness of OOP lies in the idea of design patterns. Nonetheless, PHP should encourage more and more programmers to take the path of OOP, no matter whether they are beginners or advanced programmers.

 

 

2. Support for Inner/Nested Class:

Inner/Nested classes are being well supported by programming languages such as C++ and Java(maybe Javascript too, not sure of this). The advantage is quite obvious, you can make your code more object-oriented and organized if use properly. It also provides a call-back advantage as introduced by this example in Java:

http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html

 

 

So you can define another class inside a class, which can access all of properties and methods of its outer class. It can be used for helper objects, which have been widely used in OOP projects. It can be used in classes that instantiate objects that belong to other closely-related classes. An inner class can be public, private or protected, while the outer class must be a public class. Heres an example of the syntax it may look like in PHP 6:

 

<?php
public class User{
  public $uid = 0;
  public $username;
  private $password;
  private $email;

  public class UserProfile{
    // codes inside
  }

  private class UserDataHelper{
    // codes inside
  }
}
?>

 

It will be great to see PHP supporting as many OOP features as possible, especially with OOP's gradually dominating the world of programming.

 

 

3. Miscellaneous:

Java has a system object with instance/member properties/methods and class/static properties/methods. This idea can be implemented into PHP, which effectively eliminates the traditional global variables. It also enables programmers to create fully object-oriented script, which is still impossible in PHP 5.

 

The system object can output text, whose usage was already demonstrated in the previous examples I provided. It has properties for server, file, session, cookie and user inputs, but these can only be edited with setter methods. On the other hand, filtering and validating user input can be carried out automatically, effectively preventing newbie programmers from making mistakes such as failure to realize the script is vulnerable to SQL injection.

 

Java allows users to create anonymous class in a similar way as anonymous function in some procedural programming languages, it is a good idea for PHP to adopt it. Anonymous class will be proved beneficial for some programmers.

 

On the other hand, support for existing OOP features may need to be enhanced. For instance, PHP currently does not allow child class extending multiple parent classes, which can be changed in PHP 6. The support for namespace and trait can also be improved in PHP 6, which I believe is not even an issue.

 

Again the purpose is to make it possible to create a fully object-oriented script. A fully object-oriented script may not be perfect, but a perfect script must be fully object-oriented.;)

 

 

These are all I can think of at this moment, lemme know what you think and if theres anything else you can add to this wishlist. thanks.

Link to comment
Share on other sites

  • Replies 123
  • Created
  • Last Reply

Top Posters In This Topic

Well it seems that the development of PHP6 has been delayed over and over again. I am not sure of the details, but seems that they are planning something big for PHP 6. Here's my wishlist for PHP6, and theres a chance some of them will be implemented in PHP 5.5.

 

It's not so much that it's delayed, more that it's just be out-right cancelled.  The big goal for PHP6 was full unicode support which would remove issues with utf8 and in generally make character encodings easier.  The problem is that they couldn't find any good way to address the issues and I guess the library that they were planning to use to handle unicode was so large and complex that it was almost like they were embedding php into that library rather than that library into php.  Since no real progress was being made, and they didn't like the library they just dropped it for now.

 

Pretty much all the other features they had planned have been implemented now as of php5.4.  They don't really see any need to make a PHP6 yet, and I am guessing they probably wont unless they get the full unicode feature implemented finally.

 

I can't really think of anything at the moment that I'd want PHP to have.  5.4 covers it pretty well by adding short array syntax, <?= always available, function call array de-referencing/immediate object method calling.  The only thing I think that might be nice still is a finally block and a way to declare two classes as friends.  Operator overloading or some kind of __cast magic function might be nice.

 

 

1. Fully Object-Oriented script:

...

 

Making the built-in types objects might be nice but I don't think it is really that necessary.  I like having the ability to do procedural programming, sometimes it easier to do something that way than the OOP way, especially for short one-time scripts you might create to solve a specific problem.  I do things like that with some frequency.  The fact that Java and C# force you to do objects for everything was something I always disliked about them.

 

If the above mentioned operator overloading and/or __cast magic methods were implemented one could make object wrappers for types fairly easily, but you'd still have to call them manually on creation, eg $s=new String("blah"); rather than just $s="blah";

 

 

 

2. Support for Inner/Nested Class:

...

 

Might be nice to have, maybe a better alternative to my small desire to declare two classes as friends.  Java's anonymous classes thing might be kind of nice too.  I did like that about Java for the brief time I spent using it.  Made implementing event handlers nice.

 

Link to comment
Share on other sites

1. There's no such thing as a perfect script.

 

2. OOP isn't the objective pinnacle of programming methodologies.

 

3. PHP will never go full OO.  It would require a complete overhaul of the underlying C code, and would break a lot of existing apps.

 

4. Design patterns aren't just something tied to OOP.

 

5. Anyone who knows what they're doing doesn't use globals outside of the superglobal arrays.  Further, globals are very possible with objects.  That's what a singleton is.  That's what static methods do.

 

I'm not trying to be Captain Buzzkill, but you seem stuck on the idea that OOP = perfection, which is ridiculous.  OOP is certainly a good methodology that is very useful when done well.  I use it in all my projects.  But it's not the answer to every problem.  It requires a fair amount of overhead.  It also doesn't fit certain scenarios.  I wouldn't use it for the guts of a financial system, for example.

 

Look up functional programming if you want to broaden your horizons.

 

---

 

As far as features I'd like to see, either Ruby or C# style properties.  Writing boilerplate get/set code sucks.  I'd also like to have the ability to label data members as read only.

Link to comment
Share on other sites

That is just straight out blasphemy! Next thing on your wishlist is to use . as a object operator right?

 

$str1 = new String("This is a String");
$str2 = new String(" and a concatenated one at that!");
$string = $str1->append($str2);
$system->output($string ->toupper());
// "This is a String and a concatenated one at that!"

It's the way of the future man.

Link to comment
Share on other sites

@ Kicken:

It would be a pity if PHP6 indeed will never come out. I am expecting much more improvement with Object oriented feature, but perhaps they have more important tasks at hands.

 

@ KevinM1:

I am not saying OOP = perfection. A perfect script requires more than just OOP, a programmer can code every line in OOP but still makes a crappy script. Nonetheless, fully object oriented code is one necessary step to create a perfect script. It is more reasonable to say that OOP = professional, procedural = amateur.

 

@ Ignace:

Nope, I do not see a need to replace single arrow -> with dot . operator. The single arrow sign is used to access object properties/methods in C++, and apparently PHP is influenced by both C++ and Java. Theres no need for PHP to become a complete copy of Java, the C syntax actually is easier to use in my point of view although Java has more OO features that can and should be implemented in PHP.

 

 

Anyway the world of programming is moving towards OOP, it already becomes a standard for good script and in not so distant future I can see fully object-oriented script taking over procedural and half-procedural-half-OO programming. Procedural programming is for amateurs, it is good and only good for complete newbies to learn programming since starting at OO can be difficult. It is a habit that intermediate and advanced programmer should get rid of before its too late.

 

 

Link to comment
Share on other sites

I am not saying OOP = perfection.

 

But you said exactly that...

 

A perfect script requires more than just OOP, a programmer can code every line in OOP but still makes a crappy script.

 

Sure, I'll agree with that.

 

Nonetheless, fully object oriented code is one necessary step to create a perfect script.

 

No it is not.

 

It is more reasonable to say that OOP = professional, procedural = amateur.

 

Wrong.

 

Procedural programming is for amateurs, it is good and only good for complete newbies to learn programming since starting at OO can be difficult. It is a habit that intermediate and advanced programmer should get rid of before its too late.

 

Wrong again.

 

 

Link to comment
Share on other sites

Procedural programming is for amateurs, it is good and only good for complete newbies to learn programming since starting at OO can be difficult. It is a habit that intermediate and advanced programmer should get rid of before its too late.

 

You clearly have no idea what you are talking about. procedural pre-dates OO, are you saying all those years there were only newbie programmers?

 

Link to comment
Share on other sites

You clearly have no idea what you are talking about.

 

Agreed.

 

I think your a bit out of your depth here. Sure, when some of the concepts of OOP finally click with you it's easy to think it is the be all and end all. The truth be known however, it's not. Don't get too enthusiastic.

Link to comment
Share on other sites

Yup.  Once again, OOP is merely one methodology among several, all of which have their pros and cons.  And to label procedural programming as amateurish is laughable.  There's a reason why C is still widely used.  It's what the linux kernel is written in and what PHP itself is written in, just to name a couple examples.

Link to comment
Share on other sites

On a somewhat related note, you can see what they have planned / what people are requesting by going tohttps://wiki.php.net/rfc.  If one had an idea for something they wanted one could submit a RFC for review and it might get developed.  You'd probably need to be willing to do some/most of that development yourself though.

 

Link to comment
Share on other sites

On a somewhat related note, you can see what they have planned / what people are requesting by going tohttps://wiki.php.net/rfc.  If one had an idea for something they wanted one could submit a RFC for review and it might get developed.  You'd probably need to be willing to do some/most of that development yourself though.

 

Sounds interesting, I may as well submit my own request regarding fully object-oriented PHP. PHP6 may as well still support procedural programming since Amateurs need it, but it should strongly encourage programmers to code in OOP. C++ does a good job on this, you can write procedural code in C++ but it works much better for OOP scripts. In PHP the advantage of OOP is not that much obvious, which is why many still use lots of procedural programming.

 

@ Ignace:

*sigh*

 

Newton did not know the theory of Relativity, but can you say he was a bad scientist?

 

The fact is that in early days some theory/methodology did not exist in the world of programming. It is the ultimate intelligence of human beings to create something out of nothing, you can say the one who first proposed OOP was one of the smartest guys in the world. However, you cant say those who did not use OOP back in the days when it was not there or not yet realized as a superior programming paradigm were stupid. Hopefully this time I am being clear enough.

Link to comment
Share on other sites

PHP6 may as well still support procedural programming since Amateurs need it

 

There's nothing amateurish about procedural programming.  Period.  Full stop.  You continuing to assert it does not make it true.  Indeed, all you're showing is your own inexperience.

 

The fact is that in early days some theory/methodology did not exist in the world of programming. It is the ultimate intelligence of human beings to create something out of nothing, you can say the one who first proposed OOP was one of the smartest guys in the world. However, you cant say those who did not use OOP back in the days when it was not there or not yet realized as a superior programming paradigm were stupid. Hopefully this time I am being clear enough.

 

Again, you don't know what you're talking about.  OO has been around, in terms of languages, since the 1970's.  Its theoretical underpinnings since the 1950's.  OO isn't some new discovery which is self-evidently better than everything else.

 

There are very real reasons why OO isn't used in every situation.  Off the top of my head:

 

Code bloat

Memory overhead

Memory management

No great way to handle true decimal math (reliance on floating point)

 

---

 

Since you keep asserting that OOP is what true professionals use (even though that's wrong), what is it that OOP does that's different/better than everything else in your eyes?

Link to comment
Share on other sites

PHP6 may as well still support procedural programming since Amateurs need it

 

There's nothing amateurish about procedural programming.  Period.  Full stop.  You continuing to assert it does not make it true.  Indeed, all you're showing is your own inexperience.

 

The fact is that in early days some theory/methodology did not exist in the world of programming. It is the ultimate intelligence of human beings to create something out of nothing, you can say the one who first proposed OOP was one of the smartest guys in the world. However, you cant say those who did not use OOP back in the days when it was not there or not yet realized as a superior programming paradigm were stupid. Hopefully this time I am being clear enough.

 

Again, you don't know what you're talking about.  OO has been around, in terms of languages, since the 1970's.  Its theoretical underpinnings since the 1950's.  OO isn't some new discovery which is self-evidently better than everything else.

 

There are very real reasons why OO isn't used in every situation.  Off the top of my head:

 

Code bloat

Memory overhead

Memory management

No great way to handle true decimal math (reliance on floating point)

 

---

 

Since you keep asserting that OOP is what true professionals use (even though that's wrong), what is it that OOP does that's different/better than everything else in your eyes?

 

 

Encapsulates amateur code? lol

Link to comment
Share on other sites

Don't get me wrong, but OOP in PHP has it's uses and I would love to see PHP expand on it's support of OOP. However, I do not believe that OOP is everything like "Hall of Famer" would like to believe, instead it is useful in some cases and a hinderance in others. It depends on what you are trying to do. I have been using PHP for about 7 years now and I like the ideals behind OOP, but in some of my projects procedural/sequential code just out power the OOP alternatives easily. As someone stated before, you don't need the language to be fully OOP for you to take advantage of the GoF Design Patterns.

Link to comment
Share on other sites

I've been coding for ~28 years now, ever since I was just knee-high to a grasshopper.  My profession involves coding.  Glad to know despite all that, I'm still an amateur.  But hey maybe one day I'll make it to the big boys' table.

Yeah I will be the first to say that I don't know as much as I would like, but even then I am still learning because my profession forces me to expand my knowledge and understand of development.
Link to comment
Share on other sites

I've been coding for ~28 years now, ever since I was just knee-high to a grasshopper.  My profession involves coding.  Glad to know despite all that, I'm still an amateur.  But hey maybe one day I'll make it to the big boys' table.

Yeah I will be the first to say that I don't know as much as I would like, but even then I am still learning because my profession forces me to expand my knowledge and understand of development.

 

Like many other professions, things are constantly growing and changing, so a huge part of your profession is constantly researching and learning new things, keeping up with the technology and concepts behind things.  So I by no means consider myself an expert at things either...but I've been around the block a few times, I've picked up a few tidbits of wisdom here and there... 

 

One thing I have learned over the years is that what looks good on paper is usually never applied in real life, because its just not feasible.  Too much red tape to cut through, hoops to jump, etc... even if for the sake of argument we accept that OOP is some kind of end-all-be-all perfection and everything else is crap, that doesn't mean a damn thing when you have a boss that tells you you have exactly n amount of time to do xyz and no you cannot change a b c or d.  You work with what you have. 

 

So what is the perfect paradigm?  The one that gets the job done under the circumstances you are in.  OP is just another inexperienced coder who found a shiny toy and is bragging about it. Give him enough time and experience in the real working world, he will see that the on-paper universe is not the same as real life, that even  "In a perfect world, this would be true" ..  even this statement is bupkis.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.