I'm pretty new to OOP and PHP. I'm using the IDE PhpStorm and it's giving me this (see below) warning on my reference to $width
.
Here is my code:
<?php
class box {
private $width;
function __construct(){
$this->width = 3;
}
}
?>
I've never seen the term "field" used before, and I'm not entirely sure what the sentence "Field declared dynamically" means.
It seems like this warning just showed up today after I updated PhpStorm. Did I do something wrong?
Also, if anyone can briefly explain what the warning means by "Note: Check is not performed on objects of type "stdClass" or derived"?
Please do File | Invalidate Caches...
and restart IDE -- your indexes seems to be corrupted/out-of-date after update.
and I'm not entirely sure what the sentence "Field declared dynamically" means.
This means that the field/property is not explicitly declared but relies on __get()
and __set()
magic methods to have it working.
In your case you do have field declared properly (the private $width;
part) -- it's just an IDE glitch that quite often happens after IDE gets updated to newer version.
Also, if anyone can briefly explain what the warning means by "Note: Check is not performed on objects of type "stdClass" or derived"?
It means exactly that: this check is not performed if the object is an instance of stdClass
or extends such class.
This is because of the nature of stdClass
-- it can accept calls to any fields (even undefined -- it will silently define it for you during runtime) and will not throw the errors that usual classes would in such cases.