Skip to content

Instantly share code, notes, and snippets.

@fgm
Last active August 29, 2015 14:06
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 fgm/4f19f2d3e2bd135aeb8b to your computer and use it in GitHub Desktop.
Save fgm/4f19f2d3e2bd135aeb8b to your computer and use it in GitHub Desktop.
<?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