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

Composer Errors using HHVM in PHP-7 Mode #5978

Closed
robfrawley opened this issue Dec 18, 2016 · 9 comments
Closed

Composer Errors using HHVM in PHP-7 Mode #5978

robfrawley opened this issue Dec 18, 2016 · 9 comments

Comments

@robfrawley
Copy link

robfrawley commented Dec 18, 2016

My composer.json:

{
    "name": "twig/twig",
    "type": "library",
    "description": "Twig, the flexible, fast, and secure template language for PHP",
    "keywords": ["templating"],
    "homepage": "http://twig.sensiolabs.org",
    "license": "BSD-3-Clause",
    "authors": [
        {
            "name": "Fabien Potencier",
            "email": "fabien@symfony.com",
            "homepage": "http://fabien.potencier.org",
            "role": "Lead Developer"
        },
        {
            "name": "Twig Team",
            "homepage": "http://twig.sensiolabs.org/contributors",
            "role": "Contributors"
        },
        {
            "name": "Armin Ronacher",
            "email": "armin.ronacher@active-4.com",
            "role": "Project Founder"
        }
    ],
    "support": {
        "forum": "https://groups.google.com/forum/#!forum/twig-users"
    },
    "require": {
        "php": "^7.0",
        "symfony/polyfill-mbstring": "~1.0"
    },
    "require-dev": {
        "symfony/phpunit-bridge": "~3.2@dev",
        "symfony/debug": "~2.7",
        "phpunit/phpunit": "~5.0"
    },
    "autoload": {
        "psr-0" : {
            "Twig_" : "lib/"
        }
    },
    "autoload-dev": {
        "psr-0" : {
            "Twig_Tests_" : "test/"
        }
    },
    "extra": {
        "branch-alias": {
            "dev-master": "2.0-dev"
        }
    },
    "minimum-stability": "dev"
}

The output of composer diagnose --verbose:

                                                        
  [ErrorException]                                      
  rtrim() expects parameter 1 to be string, null given  
                                                        

Exception trace:
 () at phar://composer.phar/bin/../src/../src/Composer/Config.php:220
 Composer\Util\ErrorHandler::handle() at n/a:n/a
 rtrim() at phar://composer.phar/bin/../src/../src/Composer/Config.php:220
 Composer\Config->get() at phar://composer.phar/bin/../src/../src/Composer/Factory.php:594
 Composer\Factory::createRemoteFilesystem() at phar://composer.phar/bin/../src/../src/Composer/Factory.php:325
 Composer\Factory->createComposer() at phar://composer.phar/bin/../src/../src/Composer/Factory.php:569
 Composer\Factory::create() at phar://composer.phar/bin/../src/../src/Composer/Console/Application.php:314
 Composer\Console\Application->getComposer() at phar://composer.phar/bin/../src/../src/Composer/Console/Application.php:426
 Composer\Console\Application->getPluginCommands() at phar://composer.phar/bin/../src/../src/Composer/Console/Application.php:131
 Composer\Console\Application->doRun() at phar://composer.phar/bin/../src/../vendor/symfony/console/Application.php:124
 Symfony\Component\Console\Application->run() at phar://composer.phar/bin/../src/../src/Composer/Console/Application.php:100
 Composer\Console\Application->run() at phar://composer.phar/bin/composer:52
 include() at /usr/local/bin/composer:25

When I run this command:

hhvm -c hhvm.ini /usr/local/bin/composer update --verbose

With the following contents in hhvm.ini:

; php options
session.save_handler = files
session.save_path = /var/lib/hhvm/sessions
session.gc_maxlifetime = 1440

; hhvm specific
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.mysql.typed_results = false

; hhvm php 7 mode
hhvm.php7.all = 1

I get the following output:

                                                        
  [ErrorException]                                      
  rtrim() expects parameter 1 to be string, null given  
                                                        

Exception trace:
 () at phar://composer.phar/bin/../src/../src/Composer/Config.php:220
 Composer\Util\ErrorHandler::handle() at n/a:n/a
 rtrim() at phar://composer.phar/bin/../src/../src/Composer/Config.php:220
 Composer\Config->get() at phar://composer.phar/bin/../src/../src/Composer/Factory.php:594
 Composer\Factory::createRemoteFilesystem() at phar://composer.phar/bin/../src/../src/Composer/Factory.php:325
 Composer\Factory->createComposer() at phar://composer.phar/bin/../src/../src/Composer/Factory.php:569
 Composer\Factory::create() at phar://composer.phar/bin/../src/../src/Composer/Console/Application.php:314
 Composer\Console\Application->getComposer() at phar://composer.phar/bin/../src/../src/Composer/Console/Application.php:426
 Composer\Console\Application->getPluginCommands() at phar://composer.phar/bin/../src/../src/Composer/Console/Application.php:131
 Composer\Console\Application->doRun() at phar://composer.phar/bin/../src/../vendor/symfony/console/Application.php:124
 Symfony\Component\Console\Application->run() at phar://composer.phar/bin/../src/../src/Composer/Console/Application.php:100
 Composer\Console\Application->run() at phar://composer.phar/bin/composer:52
 include() at /usr/local/bin/composer:25

And I expected this to happen: Composer to update my dependencies and properly recognize HHVM as meeting the following requirement:

{
    "require": {
        "php": "^7.0"
    }
}

When I run this command:

hhvm /usr/local/bin/composer update --verbose

Which doesn't include the hhvm.ini file to enable PHP 7 mode, I get the correct, expected result of:

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php ^7.0 but your HHVM version does not satisfy that requirement.

The following script:

echo sprintf(" PHP_VERSION=[%s]\nphpversion()=[%s]\n", PHP_VERSION, phpversion());

Run with php-7.1 binary, hhvm binary (no php7 mode enabled), and hhvm (with php7 mode enabled):

# /usr/bin/php7.1
PHP_VERSION= [7.1.0]
phpversion()=[7.1.0]

# /usr/bin/hhvm
PHP_VERSION= [5.6.99-hhvm]
phpversion()=[5.6.99-hhvm]

# /usr/bin/hhvm -c hhvm.ini
PHP_VERSION= [7.0.99-hhvm]
phpversion()=[7.0.99-hhvm]

Related to twigphp/Twig#2305 and twigphp/Twig#2302.

@robfrawley robfrawley changed the title Composer Errors out Using HHVM with hhvm.php7.all=1 Enabled for PHP7 Mode Composer Errors using HHVM in PHP-7 Mode Dec 18, 2016
@alcohol
Copy link
Member

alcohol commented Dec 19, 2016

It seems HHVM fails on an rtrim call (which is run over the result of a process call, which returns the result of a preg_replace_callback call). The value returned is null, which would suggest that the preg_replace_callback function error'ed.

Not sure why it would fail on that in php7 mode though.

We could add another env to our .travis.yml whereby we run hhvm in php7 mode.

@alcohol
Copy link
Member

alcohol commented Dec 19, 2016

Weird, running the test suite on hhvm with php7 mode does not result in any errors.

See #5979

@alcohol
Copy link
Member

alcohol commented Dec 19, 2016

And I expected this to happen: Composer to update my dependencies and properly recognize HHVM as meeting the following requirement:

{
    "require": {
        "php": "^7.0"
    }
}

Just to clarify though: setting hhvm to php7 mode will not make it match the php constraint, since the compiler will not be recognized as php but as hhvm. So while the rtrim error is unfortunate and I would like to determine what is causing it, your original issue cannot be resolved because your expectations are wrong.

Edit: see response from @Seldaek

@Seldaek
Copy link
Member

Seldaek commented Dec 19, 2016

@alcohol that last post is wrong, HHVM provides a PHP_VERSION constant and we use that to create the php platform package, so if PHP_VERSION is set to 7.0.99-hhvm you should see php 7.0.99 The PHP interpreter when running composer show --platform (I do if I hardcode that version instead of PHP_VERSION in the platform repository, so that doesn't seem to be the problem.

@robfrawley The rtrim failure seems like an interop bug in HHVM, rtrim definitely should not fail on NULL values, but anyway I worked around that in 1464146 and you can try again with latest Composer snapshot see if it runs further this time.

@alcohol
Copy link
Member

alcohol commented Dec 19, 2016

@Seldaek I was not aware of that. Good to know.

@robfrawley
Copy link
Author

@Seldaek There is an additional notice-level issue with another string function, but as that doesn't cause the process to halt, this fix does allow Composer to successfully run. Thanks!

The new notice is related to the same interop bug you linked to, but in this case, doesn't halt script execution, so I'd suggest it isn't fixed in Composer as it should just go away once they issue a fix for that bug. Also, it doesn't provide any information as to where it is being caused, even in verbose mode.

Anyway, cheers. Thanks for the fix.

@photodude
Copy link

@robfrawley I'm also seeing strtolower() expects parameter 1 to be string, null given causing process halting. Is that the other string function you were mentioning? Yes all of these are related to the type annotations issue in HHVM, or to running PHP 7 in strict mode. (I'm opening a new issue for the strtolower() issue)

@robfrawley
Copy link
Author

@photodude Yup; that was it!

@fredemmott
Copy link
Contributor

FYI composer should work correctlyin HHVM's PHP7 mode in 3.20.2 and later

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

No branches or pull requests

5 participants