Magic Getters and Setters
=========================
```Example from 1 languages: JavaScript
// Can be implemented in ES6 using proxies:
"use strict";
if (typeof Proxy == "undefined") {
throw new Error("This browser doesn't support Proxy");
}
let original = {
"foo": "bar"
};
let proxy = new Proxy(original, {
get(target, name, receiver) {
let rv = Reflect.get(target, name, receiver);
if (typeof rv === "string") {
rv = rv.toUpperCase();
}
return rv;
}
});
console.log(`original.foo = ${original.foo}`); // "original.foo = bar"
console.log(`proxy.foo = ${proxy.foo}`); // "proxy.foo = BAR"
```
```Example from 1 languages: PHP
public function __set($name, $value)
{
echo "Setting '$name' to '$value'\n";
$this->data[$name] = $value;
}
public function __get($name)
{
echo "Getting '$name'\n";
if (array_key_exists($name, $this->data)) {
return $this->data[$name];
}
$trace = debug_backtrace();
trigger_error(
'Undefined property via __get(): ' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'],
E_USER_NOTICE);
return null;
}
```
*
Languages *with* Magic Getters and Setters include JavaScript, PHP, Speedie
*
Languages *without* Magic Getters and Setters include C++, C3
*
View all concepts with or missing a *hasMagicGettersAndSetters* measurement
http://pldb.info/../lists/explorer.html#columns=rank~id~appeared~tags~creators~hasMagicGettersAndSetters&searchBuilder=%7B%22criteria%22%3A%5B%7B%22condition%22%3A%22null%22%2C%22data%22%3A%22hasMagicGettersAndSetters%22%2C%22origData%22%3A%22hasMagicGettersAndSetters%22%2C%22type%22%3A%22num%22%2C%22value%22%3A%5B%5D%7D%5D%2C%22logic%22%3A%22AND%22%7D missing
http://pldb.info/../lists/explorer.html#columns=rank~id~appeared~tags~creators~hasMagicGettersAndSetters&searchBuilder=%7B%22criteria%22%3A%5B%7B%22condition%22%3A%22!null%22%2C%22data%22%3A%22hasMagicGettersAndSetters%22%2C%22origData%22%3A%22hasMagicGettersAndSetters%22%2C%22type%22%3A%22num%22%2C%22value%22%3A%5B%5D%7D%5D%2C%22logic%22%3A%22AND%22%7D with
*
Read more about Magic Getters and Setters on the web: 1.
https://www.php.net/manual/en/language.oop5.overloading.php#object.get 1.
Built with Scroll v178.2.3