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

Bug: View rendering, extracted variables overwrites existed variables(arguments and etc.) #4108

Closed
WinterSilence opened this issue Jan 15, 2021 · 0 comments · Fixed by #4113
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@WinterSilence
Copy link
Contributor

WinterSilence commented Jan 15, 2021

Direction

extract($this->tempData); can overwrites existed variables

Describe the bug

extract($this->tempData);

extract($this->tempData);

It's can overwrites existed variables (arguments and etc.).

CodeIgniter 4 version
4.0.4, master

Fix

Need add wrapper-functions to capture output and keep scope resolution, for example:

function (string $viewCode, array $viewData): string {
    extract($viewData, EXTR_SKIP);
    ob_start();
    eval('?>' . $viewCode);
    return (string) ob_get_clean();
}

or

function (string $viewCode, array $viewData): string {
     $viewFileHandler = tmpfile();
     fwrite($viewFileHandler, $viewCode);
     unset($viewCode);
     extract($viewData, EXTR_SKIP);
     ob_start();
     include(stream_get_meta_data($viewFileHandler)['uri']);
     fclose($viewFileHandler);
     return (string) ob_get_clean();
}
@WinterSilence WinterSilence added the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant