Skip to content

Instantly share code, notes, and snippets.

@ilhamarrouf
Last active February 26, 2017 12:57
Show Gist options
  • Save ilhamarrouf/933ccd0ffea8b3568388b4ae21c1371b to your computer and use it in GitHub Desktop.
Save ilhamarrouf/933ccd0ffea8b3568388b4ae21c1371b to your computer and use it in GitHub Desktop.
OOP PHP
<?php
class Outer
{
private $prop = 1;
protected $prop2 = 2;
protected function func1()
{
return 3;
}
public function func2()
{
return new class($this->prop) extends Outer {
private $prop3;
public function __construct($prop)
{
$this->prop3 = $prop;
}
public function func3()
{
return $this->prop2 + $this->prop3 + $this->func1();
}
};
}
}
echo (new Outer)->func2()->func3();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment