Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning when calling hasVariable for an undefined variable #978

Merged
merged 2 commits into from Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'));
}

}