Last active
May 28, 2018 19:46
-
-
Save tentacode/8627566bb59cbed5df9bb0c208bf1984 to your computer and use it in GitHub Desktop.
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 Something | |
{ | |
public function __construct() | |
{ | |
print "J'ai été instanciée.".PHP_EOL; | |
} | |
public function __destruct() | |
{ | |
print "Chuis morte.".PHP_EOL; | |
} | |
public function __invoke() | |
{ | |
print "J'ai été invoquée.".PHP_EOL; | |
} | |
} | |
(new Something())(); | |
// équivaut à | |
$something = new Something(); | |
$something(); | |
// aussi équivaut à | |
$something2 = new Something(); | |
$something2->__invoke(); | |
// aussi équivaut à | |
$something3 = new Something(); | |
call_user_func($something3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Le truc rigolo c'est que la seule de différence entre les 4 méthodes est que la première appelle le destructeur directement après son instanciation (normal quand on y pense), ce qui affichera :