PHP 5.4 Support: Traits

Hi all! Today we would like to introduce you to another new PHP 5.4 feature for NetBeans 7.2, which is called Traits.

Note: All PHP 5.4 features are available in your projects after setting Project Properties -> Sources -> PHP Version to PHP 5.4 value, or after choosing the same value during a PHP Project creation (in New Project Wizard).

If you don't know what Traits are, just look at the official documentation or the RFC.

So what exactly is exact Trait support in NetBeans? Syntax is recognized correctly and code completion offers declared, inherited stuff from used traits.

Note: Just one thing is not supported yet - resolving name conflicts and aliasing of method names (it means that you will not have these "virtual" names in your code completion). We would like to implement it in a future NetBeans release. Sorry for any inconvenience.

PHP 5.4: Traits

That's all for today and as usual, please test it and if you find something strange, don't hesitate to file a new issue (component php, subcomponent Editor). Thanks.

Comments:

Not everyone own a server, shared hosting providers are just introducing PHP 5.3 and the support for PHP 5.4 would be little help for most people. Please do spend your valuable time on improving something usable.

Posted by SenG on April 24, 2012 at 10:41 AM CEST #

We do our best. Thanks for you response.

Posted by Ondrej Brejla on April 24, 2012 at 10:45 AM CEST #

@SenG As a professional PHP Programmer, I'd love to see better support for 5.4 in NetBeans. Sorry, I'd argue most people using a robust IDE aren't n00bs bound by shared server limitations.

Posted by guest on April 28, 2012 at 09:36 PM CEST #

Hi, what exactly you mean by "better support"? I think that we have almost everything.

Posted by Ondrej Brejla on April 30, 2012 at 08:34 AM CEST #

Hi,
When you guys are estimating the release of new netbeans supporting PHP 5.4 ?

Posted by Aashis Khanal on May 04, 2012 at 05:30 PM CEST #

I'd ignore SenG with baseless remarks like that. I look forward to this addition in NetBeans, thanks for your continued support.

Posted by SenG on May 08, 2012 at 11:04 PM CEST #

Aashis: just wait a few days for 7.2 beta, hopefully.

Posted by Ondrej Brejla on May 09, 2012 at 09:26 AM CEST #

@SenG Regarding php I'd say they have everything important covered. The things I don't like about Netbeans are with the overall system, stuff the php team probably can't do anything about. Take your complaints to a higher level.

Posted by guest on May 25, 2012 at 08:41 PM CEST #

It works well except for the use blocks, but you said that was coming.

I have on problem, though: How can I typehint the class using the trait in @return and @param metadata?

Say I have a singleton trait. The getInstance() method should @return what? I've tried @return self, @return \self and @return this, but they all seem to (rightfully, really) assume I mean classes.

I guess the problem is with the phpdoc definition, but i cannot find how to do this properly, anywhere...

Posted by guest on June 28, 2012 at 05:12 PM CEST #

Might be interesting to know, that Traits type hinting does not work, when using them in chain.

Example:
[code]
trait X {

/**
* @return self
*/
function example() {
return $this;
}

/**
* @return \self
*/
function other_example() {
return $this;
}

/**
* @return X
*/
function more_example() {
return $this;
}

/**
* @return this
*/
function what_a_example() {
return $this;
}
}

class Test {
use X;

public function abc ()
{
$this->example()->???;
$this->other_example()->???;
$this->more_example()->???;
$this->what_a_example()->????;
}

}
[/code]

None of them are able to get the correct chain, despite telling the IDE, using the @return.

Chain does work, when moving the trait function in the class, and referring to the class itself in the @return. But that in fact makes the trait ability useless.

Posted by Ben on July 30, 2012 at 02:42 AM CEST #

When i implement interface in super class via trait netbeans tells me that this interface isn't implemented in child class.

Posted by guest on November 28, 2012 at 05:21 PM CET #

It should be fixed in 7.3dev. Can you test it there [1]? Thanks.

[1] http://bits.netbeans.org/download/trunk/nightly/latest/

Posted by Ondrej Brejla on November 28, 2012 at 05:39 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This blogs is written by NetBeans developers who contribute to the PHP support mainly.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today