New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array (array<string, string|null>) does not accept key string. #2970
Comments
The |
At least the message could be better... |
Note that I also check if key if (!array_key_exists($format, $this->body)) {
throw new \InvalidArgumentException(sprintf('Format "%s" is not a valid body format.', $format));
}
if ($this->body[$format] === null) {
$this->body[$format] = 'foobar'; // Array (array<string, string|null>) does not accept key string
} |
@Kocal PHPStan now reports different result with your code snippet: @@ @@
-14: Array (array<string, string|null>) does not accept key string.
-17: Method Message::getBody() should return string but returns string|null.
+14: Array (array<string, string|null>) does not accept key string. Full report
|
@Kocal PHPStan now reports different result with your code snippet: @@ @@
-14: Array (array<string, string|null>) does not accept key string.
-17: Method Message::getBody() should return string but returns string|null.
+ 5: Property Message::$body has no typehint specified. Full report
|
@Kocal After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-14: Array (array<string, string|null>) does not accept key string.
-17: Method Message::getBody() should return string but returns string|null.
+14: Array (array('html' => string|null, 'htmlsource' => string|null, 'txt' => string|null, 'raw' => string|null, 'eml' => string|null)) does not accept key string. Full report
|
@Kocal After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-14: Array (array<string, string|null>) does not accept key string.
-17: Method Message::getBody() should return string but returns string|null.
+14: Array (array{html: string|null, htmlsource: string|null, txt: string|null, raw: string|null, eml: string|null}) does not accept key string. Full report
|
@Kocal After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-14: Array (array<string, string|null>) does not accept key string.
-17: Method Message::getBody() should return string but returns string|null.
+14: Property Message::$body (array{html: string|null, htmlsource: string|null, txt: string|null, raw: string|null, eml: string|null}) does not accept non-empty-array<string, 'foobar'>. Full report
|
@Kocal After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-14: Array (array<string, string|null>) does not accept key string.
-17: Method Message::getBody() should return string but returns string|null.
+14: Property Message::$body (array{html: string|null, htmlsource: string|null, txt: string|null, raw: string|null, eml: string|null}) does not accept non-empty-array<string, string|null>. Full report
|
This works fine https://phpstan.org/r/784dfc05-6cd8-47a8-bfa2-e51f751fa1de So it seems like PHPStan is understanding better
than
It is something to improve in ArrayKeyExistsFunctionTypeSpecifyingExtension I think, I'll take a look. |
@Kocal After the latest push in 1.9.x, PHPStan now reports different result with your code snippet: @@ @@
-14: Array (array<string, string|null>) does not accept key string.
-17: Method Message::getBody() should return string but returns string|null.
+No errors |
@Kocal After the latest push in 1.10.x, PHPStan now reports different result with your code snippet: @@ @@
-14: Array (array<string, string|null>) does not accept key string.
-17: Method Message::getBody() should return string but returns string|null.
+No errors |
Fixed: phpstan/phpstan-src#1941 |
Nice, thanks :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
I have an array
['html' => null, 'htmlsource' => null, 'txt' => null, 'raw' => null, 'eml' => null]
of typearray{html: ?string, htmlsource: ?string, txt: ?string, raw: ?string, eml: ?string}
.I'm trying to change
$array[$format]
value (where$format
is eitherhtml
,htmlsource
,txt
,raw
, oreml
), but PHPStan is throwing errorArray (array<string, string|null>) does not accept key string.
.There is also another error
Method Message::getBody() should return string but returns string|null.
. I don't know if it's related, but this is super weird since I assign a string to$this->body[$format]
if it's equals tonull
.Code snippet that reproduces the problem
https://phpstan.org/r/ec4cb784-4886-4bb8-83b8-e034fd042f55
Expected output
The static analytics should not claim the two errors.
Thanks!
The text was updated successfully, but these errors were encountered: