Created
June 6, 2011 08:29
-
-
Save naholyr/1009932 to your computer and use it in GitHub Desktop.
PHP Sadness... Callbacks as arguments
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 | |
class c { | |
public $f; | |
public function __construct() { | |
$this->f = function() { echo 'coucou'; }; | |
} | |
} | |
// Note: "public $f = function() {...}" is a syntax error... | |
$c = new c; | |
// Works (displays "coucou") | |
$f = $c->f; | |
$f(); | |
// Doesn't work (syntax error) | |
$c->f(); | |
// Of course, doesn't work either... | |
($c->f)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment