What features do you want to see in PHP6

I’m not sure I understand what you mean. Terms like private, public and protected seem to have a well-defined, albeit somewhat general meaning. Final, on the other hand, is ambiguous.

Well said. Nevertheless wouldn’t it be convenient if you could pass a string if you’re not using custom exceptions? Maybe an Exception instance could be created internally and have the string assigned as its message.

throw 'Message'

instead of

throw new Exception('Message')

Hmm. Well, it is not at all clear to me why you would want to do the former. Maybe your intention is to simply log some condition’s outcome? Besides, I don’t see how much more convenient it really is – the latter is just 15 more characters to type (less with a good IDE) and gives the handler much more information to work with.

I guess this is getting OT, so I’ll wrap it there. Cheers.

The issue with access modifiers (private, public, protected and package in Java) is that they’re handling two different things which are not related.

One thing is controlling which objects may see and call properties (attributes and methods). Generally, public means that anyone may access a property, while private restricts access to the owning object only.

The other thing is controlling whether a property gets inherited by a subclass. In this role, public means that it does, while private means that it doesn’t.

This double role of these keywords necessitated the additional keyword “protected”, which means that it is accessible as if it was private, but it inherits as if it was public.

My issue with this system is twofold:

a) I see absolutely no reason, except for the paranoia of incompetent programmers, why would a property not be inherited at all times? A class is a representative of a type, and a type is defined by the properties it displays; so if a type has some property, it’s only natural that its subtype does it as well; if it doesn’t, it’s the subtype’s responsibility to define its properties, and not the parent’s. IOW, the second role of these keywords is totally superfluous and should, ideally, be completely removed.

b) If the above would be true, a property could have only two states: visible to all (public) and visible only to the object itself (private). This means that one of this keywords is not needed, since we could determine a default state by the lack of a keyword – and IMO the default should be private and the keyword public, as public properties define our object’s interface.

An extra step could be taken by restricting the public keyword to methods only – attributes should be private and never public; if you need an attribute, use a method. Or even better, we could eliminate the attributes completely and turn them into dynamic properties defined as methods; but that might be stretching it a bit.

As for the private / protected debate: private members are indeed inherited to a certain extent in that a child class can not redeclare those member names. What this says is that the defining class is insisting on that name for its own internal use. In this way it protects itself from children classes that may otherwise abuse that member. OTOH, protected members allow child classes to do what they will. So, the argument that a type contains members that are always visible is a misnomer – there are times when a type may want to restrict its internal mechanism so that even subclasses can not access it. This, undoubtedly, will disturb those who favor a purely dynamic style of coding since for those sorts of codes, everything is usually kept entirely open without any concern for “safety”, which itself is considered a hindrance. Personally I think we can live with only two access levels in PHP but at the same time, it doesn’t bother me at all that there are 3 levels.

I wonder if that could be a smell suggesting an inheritance hierarchy should be broken up?

All I really want to see is:

  • Full Unicode support (needed especially in the string manipulation functions)
  • Array shorthand syntax $a = {1, 2, 3};
  • Support for functions and constants in declarations, like below:

function myFunction($option1 = 0, $option2 = OPT2_DEFAULT, $option3 = getOpt3Default())
{
    // etc...
}

class xyz
{
    public $option1 = 0;
    public $option2 = OPT2_DEFAULT;
    public $option3 = getOpt3Default();

    // etc...

}

Pragmatically speaking, the bigger problem is that parent and child classes are tightly coupled. I’m not sure, but I’m inclined to see this behavior as an attempt to alleviate that problem. It’s probably not a successful attempt; it’s better to find alternatives to implementation inheritance.

This is an interesting idea I’ve never thought through. My initial reaction is this: Pragmatically speaking, the bigger problem is that parent and child classes are tightly coupled. I’m not sure, but I’m inclined to see the behavior of private properties as an attempt to alleviate that problem. It’s probably not a very successful attempt; it’s better to find alternatives to implementation inheritance.

You can already use constants, and I’m not sure being able to use functions is truly required, since you can easily work around it.

Throw an Exception instance, just have internals take care of instantiation.

Same reason shorthand notation exists in for example JavaScript, Python and CSS: brevity. I guess it’s a matter of taste.

Sorry, just had to point something out here, albeit, something IE kindly haven’t implemented:

Unicode support!

Everything else can wait for PHP7 imho.

I am starting using PHP 5.3 in real project. I have found some missing features in PHP 5.3

You do realise that this thread is 3 years old, right?