Skip to content

Instantly share code, notes, and snippets.

@fgm
Created September 20, 2014 09:46
Show Gist options
  • Save fgm/947420f3f8486225307a to your computer and use it in GitHub Desktop.
Save fgm/947420f3f8486225307a to your computer and use it in GitHub Desktop.
<?php
class Person {
public $name;
public function __construct($name) {
$this->name = $name;
}
public static function getName(Person $p = NULL) {
if (!isset($p)) {
return "Anonymous";
}
else {
return $p->name;
}
}
}
function main() {
$p1 = new Person('Nemo');
$p2 = NULL;
var_dump(Person::getName($p1), $p2, Person::getName($p2));
}
main();
/* Result:
string(4) "Nemo"
NULL
string(9) "Anonymous"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment