Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // How am I supposed to call this correctly?
- // I want to be free to use closures for c1::cb...
- function f1()
- {
- echo "1";
- }
- class c1
- {
- public $cb = f1;
- public function callcb()
- {
- // this works:
- $cb = $this->cb;
- $cb();
- // the following versions don't:
- $this->cb(); // Call to undefined method c1::cb()
- ${$this->cb}(); // Function name must be a string (this is the one which IMO really should work)
- $this->$cb(); // Function name must be a string (even though I expected it to resolve to c1::f1 and fail because of that
- $this->{$this->cb}(); // Call to undefined method c1::f1
- {$this->cb}(); // } unexpected (obviously)
- ${this->cb}(); // unexpected T_OBJECT_OPERATOR
- // Note: variants 2 and 3 don't work even with public $cb='f1'.
- }
- }
- $c = new c1;
- $c->callcb();
- $page->end();
Add Comment
Please, Sign In to add comment