Skip to content

Instantly share code, notes, and snippets.

@naholyr
Created June 6, 2011 08:29
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 naholyr/1009932 to your computer and use it in GitHub Desktop.
Save naholyr/1009932 to your computer and use it in GitHub Desktop.
PHP Sadness... Callbacks as arguments
<?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