We have seen on how to declare class and now we have to define the attributes or the data member that will hold the data within the class. This tutorial will guide you to create attributes for the class.
What are Attributes for Class?
In OOPS attributes hold the data required for the class to perform its functionality. By declaring attributes you are declaring variables for the class. Attributes are used along with Access Specifiers. Different Access Specifiers used in PHP5 are public, private and protected. Default Access Specifier for an attributes in PHP5 is public.
1. Private – By declaring attribute as private the attribute can only be accessed within the class. So outside world cannot access this Attribute
2. Protected – By declaring attribute as protected the attribute can only be accessed by the derived class while performing inheritance operation but the outside world has no access to these Attribute
3. Public – By declaring attribute as public the attribute can be accessed internally and by outside world
Example:
<?php
class newClass
{
public $first;
private $second;
protected $third;
}
?>
Here i have created 3 attributes for class newClass viz first, second and third.
IMPORTANT NOTE:
Attributes can also holds object on another class. This is useful when you want to pass the specific class object to the methods of another class.
Example – Attribute holding Object
<?
class Employee {
}
class Payment {
private $emp_id;
private $Employee
private setPayment(Employee $e)
{
$this->Employee = $e;
}
}
?>
Here in the payment class i am created setPayment() method, this method accepts one parameter which is the object of Employee class. This approach of assigning object to variables is called Type Hinting in PHP5.

[...] specify the level of access that the outside world (other objects and functions) have on the data members / member functions of the class. During Inheritance operation the derived class can access the [...]
[...] of PHP5 Class Declaring Class and Initializing Class Object Define Attributes for Class Define Methods for the Class Defining Class [...]