Optimized code for reading contents of php file. by limingxinleo · Pull Request #6804 · hyperf/hyperf · GitHub
Skip to content

Optimized code for reading contents of php file.#6804

Merged
limingxinleo merged 4 commits into
hyperf:3.2from
limingxinleo:v3.1-di
Mar 7, 2026
Merged

Optimized code for reading contents of php file.#6804
limingxinleo merged 4 commits into
hyperf:3.2from
limingxinleo:v3.1-di

Conversation

@limingxinleo

Copy link
Copy Markdown
Member

原来的方法会注册一个 error handler,没有必要,默认都有 error_handler 会抛出异常。

就算没有设置 error_handler 的,也会在 parseClassByStmts 的时候直接报错。

    public function getContents(): string
    {
        set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
        try {
            $content = file_get_contents($this->getPathname());
        } finally {
            restore_error_handler();
        }
        if (false === $content) {
            throw new \RuntimeException($error);
        }

        return $content;
    }

@limingxinleo limingxinleo added this to the v3.2 milestone May 27, 2024
@BadJacky

BadJacky commented Jun 5, 2024

Copy link
Copy Markdown

@huangdijia huangdijia changed the base branch from master to 3.2 February 5, 2025 15:18
@limingxinleo limingxinleo merged commit 5c18ea6 into hyperf:3.2 Mar 7, 2026
65 checks passed
@limingxinleo limingxinleo deleted the v3.1-di branch March 7, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants