Skip to content

Commit

Permalink
Fix warning when calling hasVariable for an undefined variable (#978)
Browse files Browse the repository at this point in the history
Fixes #977
  • Loading branch information
wisskid committed Mar 29, 2024
1 parent bbd09c7 commit 3232277
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/977.md
@@ -0,0 +1 @@
- Fix warning when calling hasVariable for an undefined variable [#977](https://github.com/smarty-php/smarty/issues/977)
2 changes: 1 addition & 1 deletion src/Data.php
Expand Up @@ -290,7 +290,7 @@ public function setVariable($varName, Variable $variableObject) {
* @return bool
*/
public function hasVariable($varName): bool {
return !($this->getVariable($varName) instanceof UndefinedVariable);
return !($this->getVariable($varName, true, false) instanceof UndefinedVariable);
}

/**
Expand Down

This file was deleted.

This file was deleted.

@@ -0,0 +1,32 @@
<?php

/**
* Tests the ::hasVariable method
*/
class HasVariableTest extends PHPUnit_Smarty
{
public function setUp(): void
{
$this->setUpSmarty(__DIR__);
}


public function testInit()
{
$this->cleanDirs();
}

public function testSimpleTrue()
{
$this->smarty->assign('foo', 'bar');
$this->assertTrue($this->smarty->hasVariable('foo'));
}


public function testSimpleFalse()
{
$this->smarty->assign('foo', 'bar');
$this->assertFalse($this->smarty->hasVariable('foox'));
}

}

0 comments on commit 3232277

Please sign in to comment.