summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog/977.md1
-rw-r--r--src/Data.php2
-rw-r--r--tests/UnitTests/SmartyMethodsTests/GetTemplateVars/cache/.gitignore2
-rw-r--r--tests/UnitTests/SmartyMethodsTests/GetTemplateVars/templates_c/.gitignore2
-rw-r--r--tests/UnitTests/SmartyMethodsTests/TemplateVars/GetTemplateVarsTest.php (renamed from tests/UnitTests/SmartyMethodsTests/GetTemplateVars/GetTemplateVarsTest.php)0
-rw-r--r--tests/UnitTests/SmartyMethodsTests/TemplateVars/HasVariableTest.php32
6 files changed, 34 insertions, 5 deletions
diff --git a/changelog/977.md b/changelog/977.md
new file mode 100644
index 00000000..d41453c1
--- /dev/null
+++ b/changelog/977.md
@@ -0,0 +1 @@
+- Fix warning when calling hasVariable for an undefined variable [#977](https://github.com/smarty-php/smarty/issues/977) \ No newline at end of file
diff --git a/src/Data.php b/src/Data.php
index 582ee660..3bb7814d 100644
--- a/src/Data.php
+++ b/src/Data.php
@@ -290,7 +290,7 @@ class Data
* @return bool
*/
public function hasVariable($varName): bool {
- return !($this->getVariable($varName) instanceof UndefinedVariable);
+ return !($this->getVariable($varName, true, false) instanceof UndefinedVariable);
}
/**
diff --git a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/cache/.gitignore b/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/cache/.gitignore
deleted file mode 100644
index d88cc144..00000000
--- a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/cache/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# Ignore anything in here, but keep this directory
-*
diff --git a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/templates_c/.gitignore b/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/templates_c/.gitignore
deleted file mode 100644
index d88cc144..00000000
--- a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/templates_c/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# Ignore anything in here, but keep this directory
-*
diff --git a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/GetTemplateVarsTest.php b/tests/UnitTests/SmartyMethodsTests/TemplateVars/GetTemplateVarsTest.php
index 4aab7c3b..4aab7c3b 100644
--- a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/GetTemplateVarsTest.php
+++ b/tests/UnitTests/SmartyMethodsTests/TemplateVars/GetTemplateVarsTest.php
diff --git a/tests/UnitTests/SmartyMethodsTests/TemplateVars/HasVariableTest.php b/tests/UnitTests/SmartyMethodsTests/TemplateVars/HasVariableTest.php
new file mode 100644
index 00000000..047af7b9
--- /dev/null
+++ b/tests/UnitTests/SmartyMethodsTests/TemplateVars/HasVariableTest.php
@@ -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'));
+ }
+
+}