Skip to content

Instantly share code, notes, and snippets.

@Majkl578
Last active July 19, 2018 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Majkl578/d6054802b8286ee271c3a4ec182fca87 to your computer and use it in GitHub Desktop.
Save Majkl578/d6054802b8286ee271c3a4ec182fca87 to your computer and use it in GitHub Desktop.
<?php
$hello = 'Hello';
$world = 'World';
$speaker = new class use ($hello as public, $world as private $who) {
public function say() : void
{
echo $this->hello . ' ' $this->who, PHP_EOL;
}
};
$speaker->say(); // Hello World
$speaker->hello = 'Hola';
$speaker->say(); // Hola World
$speaker->who = 'Mundo'; // visibility error
$speaker->say();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment