Skip to content

Commit

Permalink
Merge pull request #289 from remicollet/issue-php71
Browse files Browse the repository at this point in the history
fix for PHP 7.1
  • Loading branch information
laruence committed Jun 25, 2016
2 parents 2c4951a + a51c162 commit efcf7b7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
3 changes: 0 additions & 3 deletions requests/yaf_request_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,6 @@ YAF_STARTUP_FUNCTION(request_simple){
yaf_request_simple_ce = zend_register_internal_class_ex(&ce, yaf_request_ce);
yaf_request_simple_ce->ce_flags |= ZEND_ACC_FINAL;

zend_declare_class_constant_string(yaf_request_simple_ce, ZEND_STRL("SCHEME_HTTP"), "http");
zend_declare_class_constant_string(yaf_request_simple_ce, ZEND_STRL("SCHEME_HTTPS"), "https");

return SUCCESS;
}
/* }}} */
Expand Down
35 changes: 33 additions & 2 deletions views/yaf_view_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,17 @@ static int yaf_view_simple_extract(zval *tpl_vars, zval *vars) /* {{{ */ {

if (tpl_vars && Z_TYPE_P(tpl_vars) == IS_ARRAY) {
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tpl_vars), var_name, entry) {
#if PHP_VERSION_ID < 70100
zend_class_entry *scope = EG(scope);
#else
zend_class_entry *scope = zend_get_executed_scope();
#endif
/* GLOBALS protection */
if (zend_string_equals_literal(var_name, "GLOBALS")) {
continue;
}

if (zend_string_equals_literal(var_name, "this") && EG(scope) && ZSTR_LEN(EG(scope)->name) != 0) {
if (zend_string_equals_literal(var_name, "this") && scope && ZSTR_LEN(scope->name) != 0) {
continue;
}

Expand All @@ -121,12 +126,17 @@ static int yaf_view_simple_extract(zval *tpl_vars, zval *vars) /* {{{ */ {

if (vars && Z_TYPE_P(vars) == IS_ARRAY) {
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(vars), var_name, entry) {
#if PHP_VERSION_ID < 70100
zend_class_entry *scope = EG(scope);
#else
zend_class_entry *scope = zend_get_executed_scope();
#endif
/* GLOBALS protection */
if (zend_string_equals_literal(var_name, "GLOBALS")) {
continue;
}

if (zend_string_equals_literal(var_name, "this") && EG(scope) && ZSTR_LEN(EG(scope)->name) != 0) {
if (zend_string_equals_literal(var_name, "this") && scope && ZSTR_LEN(scope->name) != 0) {
continue;
}

Expand Down Expand Up @@ -257,15 +267,24 @@ int yaf_view_simple_display(yaf_view_t *view, zval *tpl, zval *vars, zval *ret)

(void)yaf_view_simple_extract(tpl_vars, vars);

#if PHP_VERSION_ID < 70100
old_scope = EG(scope);
EG(scope) = yaf_view_simple_ce;
#else
old_scope = EG(fake_scope);
EG(fake_scope) = yaf_view_simple_ce;
#endif

if (IS_ABSOLUTE_PATH(Z_STRVAL_P(tpl), Z_STRLEN_P(tpl))) {
script = Z_STRVAL_P(tpl);
len = Z_STRLEN_P(tpl);
if (yaf_loader_import(script, len, 0) == 0) {
yaf_trigger_error(YAF_ERR_NOTFOUND_VIEW, "Failed opening template %s: %s" , script, strerror(errno));
#if PHP_VERSION_ID < 70100
EG(scope) = old_scope;
#else
EG(fake_scope) = old_scope;
#endif
return 0;
}
} else {
Expand All @@ -278,7 +297,11 @@ int yaf_view_simple_display(yaf_view_t *view, zval *tpl, zval *vars, zval *ret)
yaf_trigger_error(YAF_ERR_NOTFOUND_VIEW,
"Could not determine the view script path, you should call %s::setScriptPath to specific it",
ZSTR_VAL(yaf_view_simple_ce->name));
#if PHP_VERSION_ID < 70100
EG(scope) = old_scope;
#else
EG(fake_scope) = old_scope;
#endif
return 0;
}
} else {
Expand All @@ -288,13 +311,21 @@ int yaf_view_simple_display(yaf_view_t *view, zval *tpl, zval *vars, zval *ret)
if (yaf_loader_import(script, len, 0) == 0) {
yaf_trigger_error(YAF_ERR_NOTFOUND_VIEW, "Failed opening template %s: %s", script, strerror(errno));
efree(script);
#if PHP_VERSION_ID < 70100
EG(scope) = old_scope;
#else
EG(fake_scope) = old_scope;
#endif
return 0;
}
efree(script);
}

#if PHP_VERSION_ID < 70100
EG(scope) = old_scope;
#else
EG(fake_scope) = old_scope;
#endif

return 1;
}
Expand Down
4 changes: 4 additions & 0 deletions yaf_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ int yaf_loader_register(yaf_loader_t *loader) /* {{{ */ {
do {
zend_fcall_info fci = {
sizeof(fci),
#if PHP_VERSION_ID < 70100
EG(function_table),
#endif
function,
#if PHP_VERSION_ID < 70100
NULL,
#endif
&ret,
params,
NULL,
Expand Down

0 comments on commit efcf7b7

Please sign in to comment.