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

0
9 comments

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:

  • Disable that inspection for the time being: "Settings (Preferences on Mac) | Editor | Inspections | PHP | Code Smell | Parameters number mismatch declaration"
  • Fix the stub yourself locally and place in some .php file anywhere in the project -- IDE will use it for reference purposes
0
Avatar
Permanently deleted user

Hi,

Thanks, as a developer a PR will be the preferred route...

Yehuda

0
Avatar
Permanently deleted user

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

0

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:

<?php

/**
* (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 The input string.
* @param string $delimiters The optional delimiters contains the word separator characters
* @return string the modified string.
*/
function ucwords
($str, $delimiters = " \t\r\n\f\v") {}



$foo = 'hello|world!';
$bar = ucwords($foo);             // Hello|world!

$baz
= ucwords($foo, "|");        // Hello|World!


P.S.
Technically you can replace original files  -- .jar is ordinary .zip archive .. but I do not see any real reason to do that.

0
Avatar
Permanently deleted user

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)

 
/**
* @since 4.0
* @since 5.0
* @since 5.4.32 ucwords($str, $delimiters = " \t\r\n\f\v")
*        Added the delimiters parameter.
* @since 5.5.16 ucwords($str, $delimiters = " \t\r\n\f\v")
*        Added the delimiters parameter.
* 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) {}


[can I achieve this using (PHP 4, PHP 5 &gt;= 5.5.16) annotation?]

Thanks
Yehuda

0

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:

  • Have 2 parameters and not to worry about this moment (when new stubs are created it's the default policy -- to use latest docs version)
  • Have 2 parameters but add comment/note to the 2nd parameter desciption stating in what version it was added.
0
Avatar
Permanently deleted user

Thanks, I'll just go my merry way and contribute the changes when things will be clearer...

Yehuda

0

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

0

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.

0

Please sign in to leave a comment.