Skip to content

Instantly share code, notes, and snippets.

@sotarok
Created October 3, 2010 13:59
Show Gist options
  • Save sotarok/608584 to your computer and use it in GitHub Desktop.
Save sotarok/608584 to your computer and use it in GitHub Desktop.
<?php
/**
* Bug in 5.3 __invoke() ?
*
* @see http://news.php.net/php.internals/49801
*/
class Hoge
{
public function __invoke()
{
echo __CLASS__, PHP_EOL;
}
}
class Fuga
{
public $hoge;
public function h()
{
// callable object as a property
$this->hoge = new Hoge();
var_dump(is_callable($this->hoge)); // => true
call_user_func($this->hoge); // => "Hoge"
// $this->hoge(); // => Fatal error: Call to undefined method Fuga::hoge()
unset($this->hoge);
// in the case of closure
$this->hoge = function ()
{
echo "closure", PHP_EOL;
};
var_dump(is_callable($this->hoge)); // => true
call_user_func($this->hoge); // => "closure"
// $this->hoge(); // => Fatal error: Call to undefined method Fuga::hoge()
}
}
$d = new Fuga();
$d->h();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment