Closed muglug closed 6 years ago
Thoughts: FunctionSignatureMap.php takes around 0.04 seconds to parse/load, which shouldn't be noticeable compared to the rest of analysis. Requiring the entire file isn't going to be slow. If you have differences in the way you analyze it, there's two approaches you could take that would still be efficient:
On some systems/disks, I'd think loading hundreds of files could be slower than accessing a single larger file.
Phan's sources of information/inferences about internal functions:
"implode"
(Merged into Phan\Plugin\Internal)A tangential feature: Phan also has https://github.com/phan/phan/tree/master/.phan/internal_stubs (Phan's FunctionSignatureMap isn't an exact substitute for ReflectionFunction/ReflectionMethod - A function can have multiple alternate signatures)
See https://github.com/phan/phan/blob/0.10.4/.phan/config.php#L427-L439 for an example of this.
!extension_loaded('pcntl')
, for example, Phan will use the stub file instead of pcntl, pretend that the resulting signatures can be used as ReflectionMethod, ReflectionFunction, class constants, etc., and go on with analyzing the projects.internal_stubs is potentially useful to know if a function call would be guaranteed to result in a PHP Error (Too many/few arguments, TypeError)
Again, this is tangential, but having something like https://github.com/DefinitelyTyped/DefinitelyTyped (From typescript and node.js) would be useful for analyzing a project.
I wonder if it's necessary to combine both the signature map and stub files? The format of the function signature map is expressive enough for 99.5% of all functions and methods, and the remainder can be handled either on a case-by-case basis or by generically-typed stubs.
Also see https://github.com/phan/phan/issues/1438 . It's probably doable to import the signatures for phpstorm, but they're probably going to need a lot of manual fixing (E.g. phpstorm only supports a single signature, phpstorm might document a type as mixed
instead of int|false
, etc.
Another thought that I had was that a standardized format might be modified to include additional information. (E.g. using the array key of the number 1
)
E.g.
Extension
(e.g. apcu_fetch
is provided by apcu
, php's own functions are provided by 'core' and various other modules)
This would make it easy to swap the default signatures for an extension with a slightly different extension version. (E.g. allow a user to remove all functions that are part of xdebug 2.6 that aren't in xdebug 2.5, replace signatures that are different in 2.5 than in 2.6)
HasNoSideEffects
(Functions such as strlen, sprintf (to some degree), etc.)
(E.g. to warn about <?php sprintf(...); ?>
instead of <?= sprintf(...); ?>
ReturnValueShouldBeUsed
(e.g. Redis->get()
, etc.
Template signatures, similar to what was mentioned for psalm. E.g. array_values accepts array<mixed,T>
as the first argument and returns array<int,T>
Various other custom tags (e.g. Is this argument a class name? Is this argument a regular expression?)
Maybe add an entry such as IgnoreNullableReturn/IgnoreFalseableReturn
for signatures that different analyzers would analyze differently. E.g. phan/psalm would reduce false positives in different ways for a handful of signatures (Either by assuming a smaller set of types or larger set of types). Or OptimisticReturnType => 'int'
alongside a declared return type of int|false
.
Also, there's around 4 sources of information for documentation that would be useful (for people using PHP) to have kept in sync:
(E.g. no complete contradictions in required/optional param counts, or types, or whether something is variadic or not for a given extension version)
phpstorm stubs (E.g. FunctionSignature.php may say something is an int, phpstorm might say something is mixed/string).
This can probably be imported by a mechanism similar to what is used for .phan/internal_stubs files
Those linked scripts are messy right now and should be refactored eventually
Sorry if my question is going to be trivial, but: why not depends on native PHP's Reflection
anymore?
@carusogabriel asked and answered here: https://github.com/phan/phan/issues/494
I spoke with @artspb today and he told me that JetBrains doesn't tag their stubs repo because they don't need it, but they would be willing to do that so that other tools can use it. If that would be of use for you guys, just open a ticket in their issue tracker.
@lookyman Here's the issue https://youtrack.jetbrains.com/issue/WI-40958
@everyone Please feel free to comment there with your suggestions on how it should be done. We indeed don't need tags, so our goal is to make them usable for you.
Not sure if anyone has seen, but they've started tagging now https://github.com/JetBrains/phpstorm-stubs/releases
I think this is long-ago fixed!
Continuing on from the discussion on f486280bf7746e20661f3c917f63749915f1be59, where the diff breaks the interface
Concerning a unified format:
Psalm uses three sources of information for builtin function/method lookups:
I wonder if it's necessary to combine both the signature map and stub files? The format of the function signature map is expressive enough for 99.5% of all functions and methods, and the remainder can be handled either on a case-by-case basis or by generically-typed stubs.
Additionally the CPU, memory, and storage constraints are optimised for each use case. From a maintenance perspective, @TysonAndre and I do a pretty good job of keeping our copies of the signature map in sync, and would welcome any additional information.
cc @Majkl578 @carusogabriel @greg0ire