A variable member of a class is called a "property", or "field", "characteristic", which is known collectively as "Properties" in this document. A property declaration consists of the keyword public,protected or private, followed by a common variable declaration. A variable in a property can be initialized, but the initialized value must be a constant, where a constant is a PHP script that can get its value at compile time without relying on the information at run time to evaluate it.
Note:
For backwards compatibility with PHP 4,php 5 claims properties can still be substituted (or appended to) public,protected or private using the keyword var directly. However, Var is no longer needed. PHP 5.0 to 5.1.3,var is considered obsolete and throws a e_strict warning, but 5.1.3 is no longer considered obsolete and does not throw a warning.
If you use Var to declare a property without using either public,protected or private, PHP 5 treats it as public.
Inside a member method of a class, you can access a non-static property by using the (object operator): $this->property, where property is the name of the attribute. A static property is accessed by:: (Double-colon): Self:: $property.
Example #1 Property Declaration
Class Simpleclass
{
Wrong property declaration
Public $var 1 = ' hello '. ' World ';
Public $var 2 = <<<eod
Hello World
EOD;
Public $var 3 = 1+2;
Public $var 4 = Self::mystaticmethod ();
Public $var 5 = $myVar;
Correct property declaration
Public $var 6 = myconstant;
Public $var 7 = array (true,false);
PHP5.3.0 and later, the following statement is also correct
Public $var 8 = <<< ' EOD '
Hello World
EOD;
}
Unlike Heredocs, Nowdocs can be used in any static data context, including property declarations.
Example #2 Example: Initializing properties with Nowdoc
From PHP5.3.0
Public $var = <<< ' EOD '
Hello World
EOD;
Note:
Nowdoc support was added in PHP 5.3.0.