Skip to content

Commit

Permalink
Merge pull request #27 from llaski/bug-undefined-variable-when-null-e…
Browse files Browse the repository at this point in the history
…rror

Fixed bug when variable is null throwing undefined error
  • Loading branch information
jeremeamia committed Jan 10, 2015
2 parents 0d5d21d + 6a414c8 commit 4d89ca7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Jeremeamia/SuperClosure/ClosureParser.php
Expand Up @@ -150,7 +150,7 @@ public function getUsedVariables()
// Combine the two arrays to create a canonical hash of variable names and values
$this->usedVariables = array();
foreach ($usedVarNames as $name) {
if (isset($usedVarValues[$name])) {
if (array_key_exists($name, $usedVarValues)) {
$this->usedVariables[$name] = $usedVarValues[$name];
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Jeremeamia/SuperClosure/Test/ClosureParserTest.php
Expand Up @@ -68,6 +68,21 @@ public function testCanGetUsedVariablesFromParser()
$this->assertEquals($expectedVars, $actualVars);
}

/**
* @covers \Jeremeamia\SuperClosure\ClosureParser::getUsedVariables
*/
public function testCanGetUsedVariablesWhenOneIsNullFromParser()
{
$foo = null;
$bar = 2;
$closure = function () use ($foo, $bar) {};
$expectedVars = array('foo' => null, 'bar' => 2);
$parser = new ClosureParser(new \ReflectionFunction($closure));
$actualVars = $parser->getUsedVariables();

$this->assertEquals($expectedVars, $actualVars);
}

/**
* @covers \Jeremeamia\SuperClosure\ClosureParser::clearCache
*/
Expand Down

0 comments on commit 4d89ca7

Please sign in to comment.