Skip to content

Instantly share code, notes, and snippets.

@james-jlo-long
Created August 14, 2015 09:49
Show Gist options
  • Save james-jlo-long/1cd15de92b0ed92d1440 to your computer and use it in GitHub Desktop.
Save james-jlo-long/1cd15de92b0ed92d1440 to your computer and use it in GitHub Desktop.
<?php
class Foo {
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
class Bar extends Foo {
public function __construct($name, $job) {
parent::__construct($name);
$this->job = $job;
}
public function getUpperName() {
return strtoupper($this->name);
}
}
$foo = new Foo('JLo');
$foo->name; // "JLo"
$foo->job; // null
$foo->getUpperName(); // Exception
$bar = new Bar('JLo', 'WebDev');
$bar->name; // "JLo"
$bar->job; // "WebDev"
$bar->getUpperName(); // "JLO"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment