Psalm: 'version_compare' isn't recognized as valid sort callback

Created on 14 Jun 2019  路  3Comments  路  Source: vimeo/psalm

ERROR: InvalidArgument - src\Model\IndexModel.php:65:27 - 
Argument 2 of uksort expects callable(mixed, mixed):int, string(version_compare) provided
        uksort($versions, 'version_compare');

'version_compare' is a valid callable and for purposes of sort it satisfies that signature version_compare ( string $version1 , string $version2 ) : int (do note there is also a second three-argument signature).

bug

Most helpful comment

Instead I made callmap handling a little more robust for functions with multiple signatures.

All 3 comments

also thinking that this should be saying that argument 2 of uksort expects callable(array-key, array-key):int, rather than callable(mixed, mixed):int (unless iterator_to_array() doesn't cast to string for object keys?)

example: https://psalm.dev/r/c2c82b91d3

<?php
$a = [];

uksort($a, 'version_compare');

Psalm output (using commit bbe5773):

ERROR: InvalidArgument - 4:12 - Argument 2 of uksort expects callable(mixed, mixed):int, string(version_compare) provided

yeah I'll likely just hard-code this rule given version_compares weirdness

Instead I made callmap handling a little more robust for functions with multiple signatures.

Was this page helpful?
0 / 5 - 0 ratings