Home Tutorial Php Phpoop PHP Mutator Accessor

 
 

Share on Google+Share on Google+
PHP Mutator Accessor
Posted on: February 19, 2010 at 12:00 AM
Advertisement
In object-oriented programming, the mutator method (also called "setter") is used to initialize the member variables of a class. On the other hand accessor methods are used to get the values of the private data member.

PHP Mutator and Accessor Methods:

In object-oriented programming, the mutator method (also called "setter") is used to initialize the member variables of a class. According to the encapsulation principle the variables of the class are declared as private to protect and can be modified by a public declared function.

On the other hand accessor methods are used to get the values of the private data member.

These methods can be implemented on non-object-oriented programming language as well. In this case we have to pass the address (reference) of the variable.

PHP Mutator Method Example:

<?php

class One{

private $string;

public function mutator($arg){

$this->string=$arg;}

public function accessor(){

echo "Value is: ".$this->string;}}

$one=new One();

$one->mutator("roseindia");

$one->accessor();

?>

 

Output:

Value is: roseindia

 

Advertisement

Related Tags for PHP Mutator Accessor:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 19, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com