PHP access control modifier

PHP access control modifier

Access control modifiers restrict the functions and classes to be accessed. Following are the list of access control modifiers:

Public: This property or method can be accessed from anywhere on the script.

Private: This property or method cannot be accessed from everywhere. It can only be used by the class or the object it is a part of.

Protected: This property or method can be used by the code in the class it is a part of.

Abstract: This property or method needs to be subclassed and cannot be used directly.

Class employee
       Public $name;
       Private $salary;
$emp = new employee;
$emp->name = “emp”;
Print $emp->name
PHP constructors & destructors
Constructor methods for classes can be declared. Classes having a constructor method can call this method on each new object.
PHP’s $_GET variable is used to collect names and data from a form using the method GET.
PHP server-side validation
Server side validations work when the client side validations fail to work ( if the java script is turned off).
Post your comment
Discussion Board
Incorrect or wrong tutorial

Please check the link which saying that you can access private properties by using class objects which is not true in php.

check the below

class employee{
public $name;
private $salary = 2000;
protected $empid = 768;


$employee = new employee();
echo $employee->salary;

Pranipat Khatua 04-23-2012