Getter and Setter

PHP 5 objects support special __get() and __set() methods to access "virtual" properties that do not actually existing, but instead are emulated existing data.

<?php

class foo {
    private $int_data = array();

    function __get($var_name) {
        return $this->int_data[$var_name];
    }

    function __set($var_name, $value)
    {
        $this->int_data[$var_name] = urlencode($value);
    }
}

$a = new foo();
$a->bar = "random value";
echo $a->bar; // will print random+value

?>

Loading ...

Related Results :

  1. Getter and Setter
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of w3clan.com.
  • Any registered user can create related posts based on search term tags.

About the Author