PhpStorm doesn't see a method of Carbon\Carbon even with a typehint

When I var_dump


in this example, it returns: object(Carbon\Carbon)#3258 (3) { ["date"]=> string(26) "2019-04-11 21:23:41.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Moscow" }

As we can see, it's an object of Carbon\Carbon.
But typehinting it doesn't change anything, PhpStorm still says "Method 'toDateTimeString' not found in". Everything works, but this warning annoys me. Previously I had always been able to typehint all methods that PhpStorm couldn't see through the framework. But in this case even typehinting doesn't work. Any advice? Could be a bug?

Comment actions Permalink

Hi there,

Yes, you are typehinting $user_bandate variable ... but warning is shown for $userip['user_bandate'] (specific array element)...

Not a bug.

If you write $user_bandate = $userip['user_bandate']; .. and then use $user_bandate->toDateTimeString(); then it will work (with PHPDoc typehint).

P.S. What is $userip? I mean -- where it comes from etc? deep-assoc-completion plugin may be able to help here.

P.P.S. Have you considered using class instead of an array? There you can typehint every field, so no such issues will be present.

Comment actions Permalink

This structure is part of the CMS, so it can't be changed. I'm afraid CMS authors didn't typehint everything. But your advice worked, thank you.


Please sign in to leave a comment.