Is there a term that refers to both class and instance variables and not variables defined in methods?

StackOverflow https://stackoverflow.com/questions/16498217

  •  21-04-2022
  •  | 
  •  

The correct term would refer to both $instance_variable and $class_variable and not to $method_variable.

class {
   public $instance_variable;
   static $class_variable;
   function do_something() {
      $method_variable;
   }
}

Does class scope variables make sense?

有帮助吗?

解决方案

I would refer to them as "properties" since PHP lacks the notion of properties as defined elsewhere (C#).

Edit, moreover, properties are the very term defined in the PHP manual:

Properties

Class member variables are called "properties". You may also see them referred to using other terms such as "attributes" or "fields", but for the purposes of this reference we will use "properties". They are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration. This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

The documentation goes on to include static declarations in this definition.

Additionally, "fields" or more generally "members" could suffice, though members often include method definitions and other constructs not exclusively for storage.

From the MSDN on C# (I know this was tagged PHP but...)

Classes and structs have members that represent their data and behavior. Those members include:

Fields (C# Programming Guide) Fields are instances of objects that are considered part of a class, normally holding class data. For example, a calendar class may have a field that contains the current date.

Properties (C# Programming Guide) Properties are methods on a class that are accessed as if they were fields on that class. A property can provide protection for a class field to keep it from being changed without the object's knowledge.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top