Skip to content

Conversation

@lipemat
Copy link
Contributor

@lipemat lipemat commented Sep 19, 2023

  • Return array<int|string> if $output = 'ARRAY_N'.
  • Return array<string, int|string> if default or $output = 'ARRAY_A'.
  • Return WP_Term if default or $output = 'OBJECT'.

link https://developer.wordpress.org/reference/functions/get_term_by/#parameters

- Return `array<int|string>` if `$output = 'ARRAY_N`.
- Return `array<string, int|string>` if default or `$output = 'ARRAY_A`.
- Return `WP_Term` if default or `$output` is 'OBJECT';

@link https://developer.wordpress.org/reference/functions/get_term_by/#parameters
@szepeviktor szepeviktor merged commit e53228e into php-stubs:master Sep 19, 2023
@szepeviktor
Copy link
Member

Thank you @lipemat!

It will be public in the next release.

@johnbillion
Copy link
Contributor

Interesting that list<...> turns into array<int, ...> in the tests. I think that's because PHPStan doesn't fully enforce a list yet. Might be worth using the array syntax instead of list? Not sure.

@szepeviktor
Copy link
Member

I need 3 independent bug reports to move my dinosaur 🦕 limbs.

@szepeviktor
Copy link
Member

<?php

/**
 * @param list<string> $param1
 */
function concat(array $param1): string
{
    return join('', $param1);
}

echo concat([10 => 'do', 20 => 'it!']);

vendor/bin/phpstan analyze -l max list.php

[OK] No errors ✅

@herndlm
Copy link
Contributor

herndlm commented Sep 19, 2023

I wasn't sure anymore, but looks like list type is still only enabled via bleeding edge / feature toggle and off by default otherwise. See https://github.com/phpstan/phpstan-src/blob/1.10.35/conf/config.neon#L55

When being off it essentially makes list behave like array<int, T> AFAIK.

@szepeviktor
Copy link
Member

@herndlm Thank you!

 ------ -------------------------------------------------------------------------------------------------
  Line   list.php
 ------ -------------------------------------------------------------------------------------------------
  11     Parameter #1 $param1 of function concat expects list<string>, array{10: 'do', 20: 'it!'} given.
         💡 array{10: 'do', 20: 'it!'} is not a list.
 ------ -------------------------------------------------------------------------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants