Created
September 20, 2014 09:46
-
-
Save fgm/947420f3f8486225307a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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