Last active
October 19, 2019 20:49
-
-
Save tacoberu/348fe2868989d6d4d4a799c46ae1ede8 to your computer and use it in GitHub Desktop.
First-class class in the PHP
This file contains 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 | |
$inst = new class("> ") { | |
private $prefix; | |
function __construct(string $prefix) | |
{ | |
$this->prefix = $prefix; | |
} | |
function log($msg) | |
{ | |
echo $this->prefix . $msg; | |
} | |
} | |
dump($inst); |
This file contains 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 | |
$klass = class { | |
private $prefix; | |
function __construct(string $prefix) | |
{ | |
$this->prefix = $prefix; | |
} | |
function log($msg) | |
{ | |
echo $this->prefix . $msg; | |
} | |
} | |
dump(new $klass("> ")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment