NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Multiple Variables defined by same DocBlock


Joined: 28 May 2008
Posts: 6
Reply with quote
Unfortunately, I still have to program for PHP 4, or this would be less of an issue since PHP5 has private and public declarations, etc...but even in PHP5, it could be useful...

Anyway, I was looking for a way to define large groups of class methods or variables so that I don't have to do the same phpDoc comments over and over again like so:

Code:
/**
 * @var string $var1
 * @access private
 */
var $var1;
/**
 * @var string $var2
 * @access private
 */
var $var2;


When I looked into it online, I found some info on "DocBlock Templates" on wikipedia:

http://en.wikipedia.org/wiki/PHPDoc

This template should supposedly allow you to make a "private" or "protected" declaration, etc., one time and have it apply to all variables/methods that are within that template. The template would start like so:

Code:
/**#@+
 * @access private
 */


This template is then applied to every element until it hits the template ending comment:

Code:
/**#@-*/


It would be very useful in my opinion, to be able to define groups of variables with the DocBlock templates and have those reflected in the Code Insight, which currently doesn't appear to be reading those templates correctly at all, as doing things like the following would greatly reduce redundancy:

Code:
/**#@+
 * @var string
 * @access private
 */
var $var1, $var2, $var3, $var4, $var5, $var6;
/**#@-*/

/**#@+
 * @var bool
 * @access public
 */
var $is1, $is2, $is3, $is4, $is5, $is6;
/**#@-*/


Zend Studio, which I quit using because of it's local/remote handling does a bit of a better job in the phpDoc department, as it will actually apply the phpDoc comment to all variables in a comma delimited list of variables even if there is no "DocBlock Template". For my purposes, even doing it that way would suffice, though the Template method has more overall use.

Anyway, if there already is a way to do this and I simply don't know about it, if someone could correct me and let me know how, that would be appreciated...i've tried various things, but the phpDoc comments always only gets applied to the first variable in a comma delimited list. So, if there's a way to better comment this without separating each variable one-by-one and still get phpEd to parse it and give the code insight, that would be great.

Otherwise, I'll just leave it as my request...to support DocBlock templates...or at the very least make it so that the same comments will apply to all variables in a comma-delimited list.

Also, I know this has been brought up elsewhere, but some beautification on the phpDoc comments to have the asterisk characters lined up (subsequent lines after the first line, add one space before asterisk).

Thanks,

Kevin
View user's profileFind all posts by calamus77Send private message
Site Admin

Joined: 13 Jul 2003
Posts: 8342
Reply with quote
as of version 5.2, these constructs are fully supported in phped.
for example, if you declare your methods like below you'll see them "private" in the code explorer:

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 28 May 2008
Posts: 6
Reply with quote
Okay, so it appears, then, that the code does understand the phpDoc template...but you don't apply anything at all to variables. I actually just tried a standard docblock over a single variable made it a string and private and the code explorer showed no change...did the same thing to functions and saw an immediate change...So, then, my request is to apply phpDoc blocks to variables as completely as you do to functions.

Actually, just did some additional testing...given the code:

Code:

        /**
        * @return bool
        * @access private
        */
        function setDebugMode( $p_bOn ) { $this->DebugModeOn = $p_bOn; }
        function setTestMode( $p_bOn )  { $this->TestModeOn  = $p_bOn; }
        /**#@-*/


The above shows up as "private setDebugMode" and "private setTestMode" in the code explorer...so it's applying it correctly to both in that case. When I start typing $this->setD..., the code insight popup shows "private bool Object::setDebugMode...". That is also perfect. However, when I type $this->setT..., the code insight popup does not show "private" or "bool"...it only shows "Object::setTestMode" and does not apparently know anything about the phpDoc template. So, while the Code Explorer is working somewhat for functions and not at all for variables using phpDoc templates...the Code Insight does not understand the phpDoc templates at all.

Kevin
View user's profileFind all posts by calamus77Send private message
Site Admin

Joined: 13 Jul 2003
Posts: 8342
Reply with quote
Quote:
the code insight popup does not show "private" or "bool"...it only shows "Object::setTestMode" and does not apparently know anything about the phpDoc template

Right, and it's because there is no "template" in your code sample. Please add #@+ in the beginning and you'll get it working as you expected:


Regarding object properties, we'll extend support of phpdoc "templates" for them in the next build.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 28 May 2008
Posts: 6
Reply with quote
Ah, yep...starting the template would be good Smile

Thanks,

Kevin
View user's profileFind all posts by calamus77Send private message
Multiple Variables defined by same DocBlock
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic