Created
November 19, 2016 09:15
-
-
Save gorkamu/812c87a119c7649446f182f6832517ba to your computer and use it in GitHub Desktop.
Ejemplo de clase anónima
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 Externa | |
{ | |
private $prop = 1; | |
protected $prop2 = 2; | |
protected function func1() { | |
return 3; | |
} | |
public function func2() { | |
return new class($this->prop) extends Externa { | |
private $prop3; | |
public function __construct($prop) | |
{ | |
$this->prop3 = $prop; | |
} | |
public function func3() | |
{ | |
return $this->prop2 + $this->prop3 + $this->func1(); | |
} | |
}; | |
} | |
} | |
echo (new Externa)->func2()->func3(); // Resultado: 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment