Yii2: Fatal error: Error when compiled in HHVM

Created on 29 Aug 2016  路  21Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

Compile my yii2 project by command:

INDEX_TMP="/var/run/hhvm/fileindex"

find /var/www/html -name \*.php > $INDEX_TMP

hhvm --hphp -t hhbc -v AllVolatile=true --input-list $INDEX_TMP --output-dir /var/run/hhvm/

Yii2 throw an exception in class Session.php

private function setCookieParamsInternal()
    {
        $data = $this->getCookieParams();
        extract($data); // failed
        if (isset($lifetime, $path, $domain, $secure, $httponly)) {
            session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
        } else {
            throw new InvalidParamException('Please make sure cookieParams contains these elements: lifetime, path, domain, secure and httponly.');
        }
    }

What is the expected result?

Run yii2 application after compiled code by hhvm

What do you get instead?

extract() functions can't run in hhvm compiled. Link to issue: Fatal error: Could not create variable environment (repo mode only)

Additional info

| Q | A |
| --- | --- |
| Yii version | 2.0.9 |
| PHP version | 7.0.8 |
| Operating system | Centos 7 |

hhvm compatibility bug

Most helpful comment

22a224d232f23502bc2bfa3afce38dd337513b5a

All 21 comments

Seems it's not going to be fixed in HHVM. Am I right?

Yes. Should use other function for extract array to variables.

how comes view rendering works in HHVM then?

@thanhpv-h9 is talking about compiling code for HHVM. So far we've checked VM-runtime version.

Should use other function for extract array to variables.

I am afraid this is not possible. I can not imagive the way to emulate extract() behavior.

There could be a fix for setCookieParamsInternal(), so it does not use extract() function.
But HHVM will still fail on any attempt to use View::render() anyway.

I can not imagive the way to emulate extract() behavior.

Although, I can:

foreach ($array as $key => $value) {
    $$key = $value;
}

However, I am unsure if it work on HHVM either.

@thanhpv-h9 can you check if @klimov-paul solution works?

Works as expected: https://3v4l.org/fvemu

Replaced $$key with ${$key} to make it a bit more readable

Works as expected: https://3v4l.org/fvemu

It does not prove anything - extract() also works on 3v4l: https://3v4l.org/t1cZ1

@rob006 it works in runtime but fails compiling.

@SilverFire have you measured performance?

I suppose the fix should be reverted.

Actually, it is weird to think direct dynamic vars creation works, while standard extract() fails.
Either it is a bug of HHVM or they should fail both at least. Or they shoulb both work.

See comment: https://github.com/facebook/hhvm/issues/6840#issuecomment-200058514

This violates the assumptions made by repo-authoritative mode

It seems both ways will fail on 'repo-authoritative mode'. Thus I can not see the way we can support it.

Commit f7bd7c2 should be reverted.

Note: that usage of extract() at Session::setCookieParamsInternal() is not necessary at all. We can use its source array just as well.

The only place we can not do anything with extract() is view rendering.

it works in runtime but fails compiling.

I've verified that HHVM compiles project after my patch, but did not verified that it failed before.

Verified on Ubunty 14.04 with

# hhvm --version
HipHop VM 3.11.1 (rel)
Compiler: 3.11.1+dfsg-1ubuntu1
Repo schema: 2f678922fc70b326c82e56bedc2fc106c2faca61

Commit is reverted eb02b36

Good, however this is not over yet.
We should get rid of extract() usage at Session::setCookieParamsInternal() and use plain array there.

@thanhpv-h9 could you check your HHVM version?

22a224d232f23502bc2bfa3afce38dd337513b5a

Was this page helpful?
0 / 5 - 0 ratings