在这种情况下,“动态声明字段"是什么意思? [英] What does 'field declared dynamically' mean in this situation?

查看:79
本文介绍了在这种情况下,“动态声明字段"是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对OOP和PHP还是很陌生.我正在使用IDE PhpStorm,并在我引用$width时向我发出此警告(见下文).

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.

这是我的代码:

<?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.

似乎我在更新PhpStorm之后才出现此警告.我做错什么了吗?

It seems like this warning just showed up today after I updated PhpStorm. Did I do something wrong?

此外,如果有人可以通过注意:不对类型为"stdClass"或派生对象的对象进行检查"来简要解释警告的含义?

Also, if anyone can briefly explain what the warning means by "Note: Check is not performed on objects of type "stdClass" or derived"?

推荐答案

请执行 File | Invalidate Caches... 并重新启动IDE-您的索引在更新后似乎已损坏/已过期.

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.

这意味着没有明确声明字段/属性,而是依靠__get()__set()魔术方法来使它起作用.

This means that the field/property is not explicitly declared but relies on __get() and __set() magic methods to have it working.

在您的情况下,您确实有正确声明的字段(private $width;部分)-这只是IDE更新在IDE更新到更高版本后经常发生的故障.

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.

此外,如果有人可以通过注意:不对类型为"stdClass"或派生对象的对象执行检查"来简要解释警告的含义?

Also, if anyone can briefly explain what the warning means by "Note: Check is not performed on objects of type "stdClass" or derived"?

这恰好意味着:如果对象是stdClass的实例或扩展了此类,则不会执行此检查.

It means exactly that: this check is not performed if the object is an instance of stdClass or extends such class.

这是由于stdClass的性质所致-它可以接受对任何字段的调用(甚至是未定义的-它将在运行时为您静默定义它),并且不会抛出普通类在这种情况下会出现的错误

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.

这篇关于在这种情况下,“动态声明字段"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆