Skip to content

Instantly share code, notes, and snippets.

@FernandoBasso
Last active May 18, 2016 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FernandoBasso/894b275642473c9698a2e529e5bbdbac to your computer and use it in GitHub Desktop.
Save FernandoBasso/894b275642473c9698a2e529e5bbdbac to your computer and use it in GitHub Desktop.
<?php
class Person {
private $name;
public function __construct($name = '') {
$this->name = $name;
}
public function __isset($key) {
return isset($this->$key);
}
public function __get($key) {
return $this->$key;
}
}
$p1 = new Person('Yoda');
$p2 = new Person();
if (empty($p1->name)) {
echo 'p1 name is empty' . PHP_EOL;
}
else {
echo $p1->name . PHP_EOL;
}
if (empty($p2->name)) {
echo 'p2 name is empty' . PHP_EOL;
}
else {
echo $p2->name . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment