Declaring
and Accessing Properties
Properties are declared in PHP using
one of the PPP operators, followed by their name:
class foo {
public $bar;
protected $baz;
private $bas;
public var1 = "Test"; // String
public var2 = 1.23; // Numeric value
public var3 = array (1, 2, 3);
}
Note that, like a normal variable, a
class property can be initialized while it is being declared. However, the
initialization is limited to assigning values (but not by evaluating
expressions). You can’t, for example, initialize a variable by calling a function—that’s
something you can only do within one of the class’ methods (typically, the
constructor).
0 Comment to " PHP Declaring and Accessing Properties "
Post a Comment