Community
Participate
Working Groups
Hi, I tested that for a method that returns an object the PHP doc "@return static" works. But for a method that returns an array of objects the PHP doc "@return static[]" doesn't give any autocompletion. It would be useful if it worked also. Thanks, best regards, Laurent Lyaudet
Hi Laurent, please could you provide us a little example of a working case (for "@return static") and a non-working case (for "@return static[]") ?
Hi Thierry, Here is a sample code to test the autocompletion. Best regards, Laurent Lyaudet <?php class A{ public $tabOChildren; /** * @return static */ public static function make(){ return new static(); } /** * @return static[] */ public function getTabOChildren(){ return $this->tabOChildren; } } class B extends A{ public function willAppearOnBAutocompleteNotA(){ } } $oB = B::make(); $oB->willAppearOnBAutocompleteNotA();//autocomplete sucessfull $tabOB = $oB->getTabOChildren(); $oB2 = $tabOB[0]; //$oB2-> no autocompletion $oB3 = reset($tabOB); //$oB3-> no autocompletion ?>
Hi Laurent, actually "@return static" and "@return static[]" are not valid (see https://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.return.pkg.html), it should be "@return A" and "@return A[]", because "static" is seen in the PHPDoc as a class name. "static" has no special meaning in phpdocs (same for "self", ...). And yes, there could be some improvements for "reset($tabOB);", maybe the day when php uses same syntax as the java language and its Generic Types, for example "<T> T reset(T $param)" so erasure would offer more powerful autocompletion hints ;)
Hi Thierry, Indeed the documentation of PHPDoc is out of date compared to what has been implemented in many IDEs (such as eclipse for @return static). I wanted to do a feature request there : https://sourceforge.net/projects/phpdoc/?source=directory But the project is deprecated. I assume Eclipse and other IDEs are free to implement the best possible improvements to the original specifications of PHPDoc. Best regards, Laurent
I forgot to say that reset($tabOB) doesn't erase the array. It just resets the iterator to loop through the array. You can do more complicated loops than foreach by using reset() and each(). I used it occasionally where foreach was inappropriate. I also often use reset alone since it returns the first element of the array, which is useful when its key in the array is not 0. Best regards, Laurent
(In reply to Laurent Lyaudet from comment #4) > Hi Thierry, > Indeed the documentation of PHPDoc is out of date compared to what has been > implemented in many IDEs (such as eclipse for @return static). > I wanted to do a feature request there : > https://sourceforge.net/projects/phpdoc/?source=directory > But the project is deprecated. > > I assume Eclipse and other IDEs are free to implement the best possible > improvements to the original specifications of PHPDoc. > > Best regards, > Laurent Yes, sorry, you're actually right, it seems that "self", "static" and "$this" can be used as phpdoc keywords: https://www.phpdoc.org/docs/latest/guides/types.html
(In reply to Laurent Lyaudet from comment #5) > I forgot to say that reset($tabOB) doesn't erase the array. > It just resets the iterator to loop through the array. > You can do more complicated loops than foreach by using reset() and each(). > I used it occasionally where foreach was inappropriate. > > I also often use reset alone since it returns the first element of the > array, which is useful when its key in the array is not 0. > > Best regards, > Laurent Yes maybe we should handle current(), reset(), next() and prev() in a special way, or create some special phpdoc tag to use with functions that return same type than their unique (input) parameter...
New Gerrit change created: https://git.eclipse.org/r/103622
Gerrit change https://git.eclipse.org/r/103622 was merged to [master]. Commit: http://git.eclipse.org/c/pdt/org.eclipse.pdt.git/commit/?id=f6f9a19bca8e88c609e3564c160d0b84d341a423
For info: my patch makes "@return static[]" work like "@return static" now. But there is still room for improvement (this will be another patch), because actually keyword "self" does the same as "static" or "$this", but it shouldn't. In phpdocumentor, it is said that: self: An object of the class where this type was used, if inherited it will still represent the class where it was originally defined. static: An object of the class where this value was consumed, if inherited it will represent the child class. (see late static binding in the PHP manual). $this: This exact object instance, usually used to denote a fluent interface. Also http://php.net/manual/en/language.oop5.late-static-bindings.php explains the difference between "self" and "static"