PHP Documentation and auto-complete not up to date
Hi,
I am trying to asses if I am missing something before submitting a bug report...
I am using ucwords() with two parameters, the latter being delimiters as added in late 5.3 and 5.4 versions. I am developing in 5.6 with all relevant configuration set.
Yet, the IDE is screaming about the method call using two parameters while the signature having only one.
The manual for ucwords: https://secure.php.net/manual/en/function.ucwords.php
The stub in PhpStorm 9 with php 5.6 configured:
/**
* (PHP 4, PHP 5)<br/>
* Uppercase the first character of each word in a string
* @link http://php.net/manual/en/function.ucwords.php
* @param string $str <p>
* The input string.
* </p>
* @return string the modified string.
*/
function ucwords ($str) {}
This might be a single occasion, and it might not.
How are the stubs created and how can I follow the process to make sure my code is inline with the manual?
Yehuda
Please sign in to leave a comment.
Hi there,
You can submit PR to the https://github.com/JetBrains/phpstorm-stubs and once accepted it will be included with the next PhpStorm version.
If you do not want to participate in the above -- just submit new ticket to the Issue Tracker and devs will fix it themselves (although I cannot say if it will be faster or slower compared to your own PR).
In mean time you may:
Hi,
Thanks, as a developer a PR will be the preferred route...
Yehuda
Another quick question:
How can I disable the standard library so I can test the phpstorm-stubs I am editing instead of those included in PhpStorm?
I want the inspection, only I want it from the project, not from phpstorm libraries.
Yehuda
You cannot disable it.
Place fixed stub in some .php file anywhere in the project -- IDE will use it instead (especially if it's in the same file where sample code is used). For example:
P.S.
Technically you can replace original files -- .jar is ordinary .zip archive .. but I do not see any real reason to do that.
Hi,
Thanks, now I see that I can test it when copying to the same file.
But how can I annotate the signature change based on the version? I couldn't find an example.
I am trying to do this (according to phpdoc it should work)
No clue.
As far as I'm aware that's what they are working on right now -- how to have versioned stubs.
At very least these new "@since 4.0" tags which they started adding recently is for PHP versions (so it works with PHP Language Level setting in IDE) -- unfortunately I have no clue how different signatures (for different versions) are planned to be handled...
Right now I may only suggest:
Thanks, I'll just go my merry way and contribute the changes when things will be clearer...
Yehuda
Andriy,
I am fiddling with a similar problem: PDOStatement::setFetchMode() has no less than four signatures, but only the first one is covered in the builtin stub. From the PHP online documentation:
public bool PDOStatement::setFetchMode ( int $mode )
public bool PDOStatement::setFetchMode ( int $PDO::FETCH_COLUMN , int $colno )
public bool PDOStatement::setFetchMode ( int $PDO::FETCH_CLASS , string $classname , array $ctorargs )
public bool PDOStatement::setFetchMode ( int $PDO::FETCH_INTO , object $object )
How do I create a stub for such an overloaded method? I would love to contribute some PRs to the GitHub project, but I have no idea how to achieve this.
Best,
Willy
TBH -- no idea.
PHP does not allow method overloading in ordinary PHP classes (when the same method has different signatures / declared more than once in the same class) -- that's why you usually would declare no function parameters at all and then handle all individual cases via func_get_args() and alike inside the actual method (FirePHP is the first that comes to my mind / from personal experience). But that is possible if it's done as an actual PHP compiled extension (done in C).
Since PHPDoc is made to work with PHP code .. it also does not have any mechanisms to describe the same method with multiple signatures (you can describe methods multiple times but at least IDE will mark them as duplicates)
------
ATM I may only suggest to submit the ticket to the Issue Tracker and see what devs can do with this.