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 symbol_table op #468

Merged
merged 2 commits into from
Mar 24, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions tests/pr468.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
--TEST--
PR #468 Check for sysboml table bug
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.use_namespace=0

--FILE--
<?php
require "build.inc";
startup();

$config = array(
"application" => array(
"directory" => APPLICATION_PATH,
"dispatcher" => array (
"catchException" => true,
),
"library" => array(
),
),
);

file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract {
public function _initConfig(Yaf_Dispatcher \$dispatcher) {
Yaf_Registry::set("config", Yaf_Application::app()->getConfig());
}
}
PHP
);


$value = NULL;

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
class IndexController extends Yaf_Controller_Abstract {
public function init() {}

public function indexAction() {
\$this->getView()->assign("ref", "ref-source");
\$this->getView()->display("index/index.phtml", ["ref" => "ref-changed"]);
return false;
}
}
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "<?php
var_dump(\$ref);
?>");

$app = new Yaf_Application($config);
$app->bootstrap()->run();

?>
--CLEAN--
<?php
require "build.inc";
shutdown();
?>
--EXPECTF--
string(11) "ref-changed"

8 changes: 3 additions & 5 deletions views/yaf_view_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,15 @@ static int yaf_view_simple_valid_var_name(char *var_name, int len) /* {{{ */
static zend_array *yaf_view_build_symtable(zval *tpl_vars, zval *vars) /* {{{ */ {
zval *entry;
zend_string *var_name;
zend_array *symbol_table;
HashTable *symbol_table;
#if PHP_VERSION_ID < 70100
zend_class_entry *scope = EG(scope);
#else
zend_class_entry *scope = zend_get_executed_scope();
#endif

symbol_table = emalloc(sizeof(zend_array));

ALLOC_HASHTABLE(symbol_table);
zend_hash_init(symbol_table, 8, NULL, ZVAL_PTR_DTOR, 0);
zend_hash_real_init(symbol_table, 0);

if (tpl_vars && Z_TYPE_P(tpl_vars) == IS_ARRAY) {
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tpl_vars), var_name, entry) {
Expand Down Expand Up @@ -142,7 +140,7 @@ static zend_array *yaf_view_build_symtable(zval *tpl_vars, zval *vars) /* {{{ */
}

if (yaf_view_simple_valid_var_name(ZSTR_VAL(var_name), ZSTR_LEN(var_name))) {
if (EXPECTED(zend_hash_add_new(symbol_table, var_name, entry))) {
if (EXPECTED(zend_hash_update(symbol_table, var_name, entry))) {
Z_TRY_ADDREF_P(entry);
}
}
Expand Down