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.

See Visibility for more
information on the meanings
of public, protected,
and private.

Note:

In order to maintain backward compatibility with PHP 4, PHP 5 will
still accept the use of the keyword var in
property declarations instead of (or in addition
to) public, protected,
or private. However, var is
no longer required. In versions of PHP from 5.0 to 5.1.3, the use
of var was considered deprecated and would
issue an E_STRICT warning, but since PHP
5.1.3 it is no longer deprecated and does not issue the warning.

If you declare a property using var instead of
one of public, protected,
or private, then PHP 5 will treat the property
as if it had been declared as public.

Within class methods non-static properties may be accessed by using
-> (Object Operator): $this->property
(where property is the name of the property).
Static properties are accessed by using the :: (Double Colon):
self::$property. See Static Keyword
for more information on the difference between static and non-static properties.

The pseudo-variable $this is available inside
any class method when that method is called from within an object
context. $this is a reference to the calling
object (usually the object to which the method belongs, but
possibly another object, if the method is called
statically from the context
of a secondary object).

The subtle change of removing the $ before accesses of $foo fixes this:

class MyClass{ private $foo = FALSE;

public function __construct() { $this->foo = TRUE;

echo($this->foo); }}

$bar = new MyClass();

I guess because it's treating $foo like a variable in the first example, so trying to call $this->FALSE (or something along those lines) which makes no sense. It's obvious once you've realised, but there aren't any examples of accessing on this page that show that.

$this can be cast to array. But when doing so, it prefixes the property names/new array keys with certain data depending on the property classification. Public property names are not changed. Protected properties are prefixed with a space-padded '*'. Private properties are prefixed with the space-padded class name...

This is documented behavior when converting any object to an array (see </language.types.array.php#language.types.array.casting> PHP manual page). All properties regardless of visibility will be shown when casting an object to array (with exceptions of a few built-in objects).

To get an array with all property names unaltered, use the 'get_object_vars($this)' function in any method within class scope to retrieve an array of all properties regardless of external visibility, or 'get_object_vars($object)' outside class scope to retrieve an array of only public properties (see: </function.get-object-vars.php> PHP manual page).

Do not confuse php's version of properties with properties in other languages (C++ for example). In php, properties are the same as attributes, simple variables without functionality. They should be called attributes, not properties.

The subtle change of removing the $ before accesses of $foo fixes this:

class MyClass
{
private $foo = FALSE;

public function __construct()
{
$this->foo = TRUE;

echo($this->foo);
}
}

$bar = new MyClass();

I guess because it's treating $foo like a variable in the first example, so trying to call $this->FALSE (or something along those lines) which makes no sense. It's obvious once you've realised, but there aren't any examples of accessing on this page that show that.