Skip to content

Instantly share code, notes, and snippets.

@bobthecow
Created October 30, 2010 21:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobthecow/655784 to your computer and use it in GitHub Desktop.
Save bobthecow/655784 to your computer and use it in GitHub Desktop.
<?php
require_once '../Mustache.php';
class MustacheCallTest extends PHPUnit_Framework_TestCase {
public function testCallEatsContext() {
$foo = new Foo();
$foo->name = 'Bob';
$template = '{{# foo }}{{ label }}: {{ name }}{{/ foo }}';
$data = array('label' => 'name', 'foo' => $foo);
$m = new Mustache($template, $data);
$this->assertEquals('name: Bob', $m->render());
}
}
class Foo {
public $name;
public function __call($method, $args) {
return 'unknown value';
}
}
@bobthecow
Copy link
Author

If mustache tests for the presence of a method in the current context with is_callable(), __call will always win. It trumps anything in the parent context -- $label in this case. It also trumps the public $name member variable. The output of this test would be:

unknown value: unknown value

Which is obviously not what anyone intended.

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