Last active
February 26, 2017 12:57
-
-
Save ilhamarrouf/933ccd0ffea8b3568388b4ae21c1371b to your computer and use it in GitHub Desktop.
OOP PHP
This file contains hidden or 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 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