Last active
August 29, 2015 14:06
-
-
Save fgm/4f19f2d3e2bd135aeb8b 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 function getName() { | |
return $this->name; | |
} | |
} | |
function main() { | |
$p1 = new Person('Nemo'); | |
$p2 = NULL; | |
var_dump($p1->getName()); | |
var_dump($p2); | |
var_dump($p2->getName()); | |
} | |
main(); | |
/* Result: | |
string(4) "Nemo" | |
NULL | |
PHP Fatal error: Call to a member function getName() on a non-object in (somepath)/syntax/nilmethod1.php on line 20 | |
PHP Stack trace: | |
PHP 1. {main}() (somepath)/syntax/nilmethod1.php:0 | |
PHP 2. main() (somepath)/syntax/nilmethod1.php:23 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment