Created
October 3, 2010 13:59
-
-
Save sotarok/608584 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* 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