Undefined class object Follow
Answered
/**
* @param MyClass|MySecondClass|object $myArgument
*
* @return array
*/
private function myMethod(object $myArgument): array
{
The `object` in the DocBlock is highlighted and the message says: "Undefined class object".
This is not correct as the `object` type is allowed by PHP.
Please sign in to leave a comment.
Hello,
I cannot reproduce this in 2018.1.4 and 2018.2 EAP.
What PhpStorm version do you run?
I have the same warning shown for my source code, using 2018.1.5 - all plugins etc. are up to date. In my example I am using the following docblock:
Even adding "object" as type hint in the function definition as is allowed in PHP 7.2 does not change the warning about the docblock (although PHPStorm does not complain about the object typehint - I have set the PHP version to 7.2)
My version is this:
PhpStorm 2018.1
Build #PS-181.4203.565, built on March 28, 2018
JRE: 1.8.0_152-release-1136-b20 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.4
And those are the screenshots:
Just updated the IDE:
PhpStorm 2018.1.5
Build #PS-181.5281.19, built on June 7, 2018
JRE: 1.8.0_152-release-1136-b39 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.4
Problem still remains...
Could you please check if renaming "object" to something else helps?
There was a similar issue with classes named after reserved words.
Everything else works - if I use "string" instead of "object" it works fine in terms of displaying a warning. When I write "obje" it even offers to autocomplete to object - but then complains that object is undefined. The name of the variable does not seem to matter either.
I also tried it in different contexts and classes - the warning is always shown.
But I want to use exactly the reserved word: this method accepts two kind of classes: `EntityA` and `EntityB`.
But I cannot type hint for both, so I use the generic `object`.
Then in the method I check for the real type and throw an exception if the passed `object` is not a type of one of the two allowed
So, I don't need to rename anything as I'm using a reserved word and want to use it.
The problem is that PHPStorm doesn't understand that the reserved word that I'm using is a reserved one and that it really exists.
Found a related issue: https://youtrack.jetbrains.com/issue/WI-41977. Please feel free to vote/comment
Try changing your PHP language level to 7.2 or greater.
Also have a same trouble.
PHP 7.4
PhpStorm 2021.1.2 Build #PS-211.7142.44
Windows 10 Pro 64
Please describe the problem you're experiencing in details & attach screenshots if possible.
The originally reported problem doesn't occur in 2021.1.2.
Have the same problem with 2021.3.1:
Try to update to 2021.3.2. Checking it in that version & I'm not seeing this problem.