Skip to content

Margus Roo –

If you're inventing and pioneering, you have to be willing to be misunderstood for long periods of time

  • Cloudbreak Autoscale fix
  • Endast

PHP Getters Setters

Posted on August 10, 2010 - August 10, 2010 by margusja


class Test {

// Set a private property. You can't get is directly
private $data = array();

// get a property
public function __get($name) {
return $this->data[$name];
}

// set a property
public function __set($name, $value) {
$this->data[$name] = $value;
}
}

// create object
$test = new Test;

// first property
$test->firstName = "Margus";
echo "Firstname = ".$test->firstName;

// second property
$test->lastName = "Roo";
echo "Lastname = ".$test->lastName;

Tulemus:

Firstname = Margus

Lastname = Roo

Posted in Linux

Post navigation

RIP
Kitarrimäng on ohtlik!

Leave a Reply

You must be logged in to post a comment.

The Master

Categories

  • Apache
  • Apple
  • Assembler
  • Audi
  • BigData
  • BMW
  • C
  • Elektroonika
  • Fun
  • Hadoop
  • help
  • Infotehnoloogia koolis
  • IOT
  • IT
  • IT eetilised
  • Java
  • Langevarjundus
  • Lapsed
  • lastekodu
  • Linux
  • M-401
  • Mac
  • Machine Learning
  • Matemaatika
  • Math
  • MSP430
  • Muusika
  • neo4j
  • openCL
  • Õpetaja identiteet ja tegevusvõimekus
  • oracle
  • PHP
  • PostgreSql
  • ProM
  • R
  • Turvalisus
  • Varia
  • Windows
Proudly powered by WordPress | Theme: micro, developed by DevriX.