Skip to content

Instantly share code, notes, and snippets.

@jhartikainen
Created June 9, 2011 10:54
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 jhartikainen/1016524 to your computer and use it in GitHub Desktop.
Save jhartikainen/1016524 to your computer and use it in GitHub Desktop.
<?php
$obj = new stdClass();
$obj->foo = function() { };
//BOOM!
$obj->foo();
//Fatal error: Call to undefined method stdClass::foo()
// :(
Copy link

ghost commented Jun 9, 2011

<?php
// Ref: http://php.net/manual/de/functions.anonymous.php

// try
call_user_func($obj->foo);

// or
$foo = $obj->foo;
$foo();

// or magic functions in combination with
$myFunctions['foo'] = function() {};
$myFunctions['foo']();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment