Skip to content

Instantly share code, notes, and snippets.

@gorkamu
Created November 19, 2016 09:15
Show Gist options
  • Save gorkamu/812c87a119c7649446f182f6832517ba to your computer and use it in GitHub Desktop.
Save gorkamu/812c87a119c7649446f182f6832517ba to your computer and use it in GitHub Desktop.
Ejemplo de clase anónima
<?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