public
Last active

  • Download Gist
MustacheCallTest.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<?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';
}
}

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.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.