diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ba55fd6d1c..e5009f91212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Fixed `Phalcon\Mvc\Model` to correctly add error when try to save empty string value to not null and not default column [#12688](https://github.com/phalcon/cphalcon/issues/12688) - Fixed `Phalcon\Validation\Validator\Uniqueness` collection persistent condition - Fixed `Phalcon\Loader::autoLoad` to prevent PHP warning [#12684](https://github.com/phalcon/cphalcon/pull/12684) +- Fixed params view scope for PHP5 [#12648](https://github.com/phalcon/cphalcon/issues/12648) # [3.0.4](https://github.com/phalcon/cphalcon/releases/tag/v3.0.4) (2017-02-20) - Fixed Isnull check is not correct when the model field defaults to an empty string. [#12507](https://github.com/phalcon/cphalcon/issues/12507) diff --git a/phalcon/mvc/view.zep b/phalcon/mvc/view.zep index 3db6baa34bd..729323dc187 100644 --- a/phalcon/mvc/view.zep +++ b/phalcon/mvc/view.zep @@ -846,7 +846,7 @@ class View extends Injectable implements ViewInterface * Create a virtual symbol table. * Variables are shared across symbol tables in PHP5 */ - if is_php_version("5") { + if PHP_MAJOR_VERSION == 5 { create_symbol_table(); } diff --git a/tests/unit/Mvc/ViewTest.php b/tests/unit/Mvc/ViewTest.php index b79c733f553..1b2ed088a7c 100644 --- a/tests/unit/Mvc/ViewTest.php +++ b/tests/unit/Mvc/ViewTest.php @@ -994,6 +994,40 @@ function () { ); } + /** + * Tests params view scope + * + * @issue 12648 + * @author Wojciech Ĺšlawski + * @since 2017-03-17 + */ + public function testIssue12648() + { + if (PHP_MAJOR_VERSION != 5) { + $this->markTestSkipped("This issue is fixed only for php5"); + } + + $this->specify( + "View params are available in local scope", + function () { + $this->_clearCache(); + $di = $this->_getDi(); + $view = new View(); + $view->setDI($di); + $view->setViewsDir(PATH_DATA . 'views' . DIRECTORY_SEPARATOR); + $view->setParamToView('a_cool_var', 'test'); + + $content = $view->setRenderLevel(View::LEVEL_ACTION_VIEW)->getRender('test3', 'another'); + expect($content)->equals("lol

test

\n"); + try { + echo $a_cool_var; + } catch (\PHPUnit_Framework_Exception $e) { + expect($e->getMessage())->contains("Undefined variable: a_cool_var"); + } + } + ); + } + private function _getDi($service = 'viewCache', $lifetime = 60) { $di = new Di();