Skip to content

"Cannot instantiate" from|trait|abstract class from #9675

Closed

Description

@PhilETaylor

Description

Im sorry but I cannot replicate this on demand. I cannot give you a test case and the details I have are very vague.

Basically, when trying to instantiate a concrete class (in production, which might mean this is when opcache is ramped up, or other caching in place), PHP will randomly throw an exception with the message in the format of the following - note this is the FULL message, the actual class is not mentioned and the message appears to be truncated.

"Cannot instantiate interface from"

"Cannot instantiate abstract class from"

"Cannot instantiate trait from"

The code for this appears to be somewhere near

static zend_always_inline zend_result _object_and_properties_init(zval *arg, zend_class_entry *class_type, HashTable *properties) /* {{{ */

Full details were first discovered when running Symfony in PHP 8.2 rc 2 in production (I know I know but someone has to lead :))

symfony/symfony#47653

A further report was then made by @julienchey in Monolog with PHP 8.1.0

Seldaek/monolog#1765

// Tagging @stof @mfn

PHP Version

Observed in 8.1.0/8.2.0rc2/8.2.0rc3

Operating System

Alpine Docker Container

Activity

  1. cmb69 commented on Oct 5, 2022

    @cmb69
    Member

    note this is the FULL message, the actual class is not mentioned and the message appears to be truncated.

    It rather looks that ZSTR_VAL(class_type->name) is "from". There might be a memory corruption.

  2. PhilETaylor commented on Oct 5, 2022

    @PhilETaylor
    Author

    Just in case - this is the opcache config from production (which itself is a docker container)

    Screenshot 2022-10-05 at 17 18 27

    Screenshot 2022-10-05 at 17 18 35

    Screenshot 2022-10-05 at 17 18 43

  3. PhilETaylor commented on Nov 13, 2022

    @PhilETaylor
    Author

    This seems resolved in PHP 8.2 RC 6 released this week so "maybe" connected to something contained in https://news-web.php.net/php.internals/118991

  4. cmb69 commented on Nov 14, 2022

    @cmb69
    Member

    Possibly. Most important is that it is fixed. :)

  5. spideyfusion commented on Dec 6, 2022

    @spideyfusion

    This issue still seems to be present in RC7. We just got hit by it in production.

    The errors only happen the first time as opcache is being built, so in our case we were able to reproduce it by reloading FPM while the application was still serving requests.

    opcache related configuration

    opcache.enable=1
    opcache.enable_cli=1
    opcache.jit=disable
    opcache.memory_consumption=256
    opcache.max_accelerated_files=100000
    opcache.validate_timestamps=0
    opcache.enable_file_override=1

    Error examples

    • Uncaught Error: Cannot instantiate interface from
    • Compile Error: Class AppBundle\ApiDoc\OpenApiResponseOK cannot extend interface tryFrom

    Other notes

    Our application is based on Symfony 5.4.16

  6. PhilETaylor commented on Dec 6, 2022

    @PhilETaylor
    Author

    Correct it is still present in RC7 - I have experienced it on every deployment but I did not want to reopen this until someone else had experienced it in case it was specific to my set up.

    I'll reopen it now.

  7. PhilETaylor commented on Dec 6, 2022

    @PhilETaylor
    Author

    @cmb69 please re-add label for "Needs Triage"

  8. spideyfusion commented on Dec 8, 2022

    @spideyfusion

    BTW, produced errors are not always related to instantiation. We also got stuff such as:

    • Symfony\Component\ExpressionLanguage\Parser::parse(): Argument #1 ($stream) must be of type Symfony\Component\ExpressionLanguage\TokenStream, Symfony\Component\ExpressionLanguage\TokenStream given
    • Compile Error: Class Doctrine\ORM\Query cannot extend interface from
  9. 12 remaining items

  10. akalineskou commented on Jan 3, 2023

    @akalineskou

    I'm also having a weird error (in production) which I cannot reproduce as it's not happening every time (opcache is enabled)

    Compile Error: Class Doctrine\\ORM\\Query\\Expr\\Select cannot extend final class from
    "file":"/var/www/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Expr/Select.php","line":12

    But as you can see, Select extends Base which is not final

    https://github.com/doctrine/orm/blob/2.14.0/lib/Doctrine/ORM/Query/Expr/Select.php
    https://github.com/doctrine/orm/blob/2.14.0/lib/Doctrine/ORM/Query/Expr/Base.php

    PHP 8.2.0 (cli) (built: Dec  8 2022 20:06:26) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.2.0, Copyright (c) Zend Technologies
        with Zend OPcache v8.2.0, Copyright (c), by Zend Technologies
    

    Edit: I also noticed the Cannot instantiate interface from
    "file":"/var/www/app/vendor/doctrine/orm/lib/Doctrine/ORM/QueryBuilder.php","line":793
    https://github.com/doctrine/orm/blob/2.14.0/lib/Doctrine/ORM/QueryBuilder.php#L793

  11. spideyfusion commented on Jan 4, 2023

    @spideyfusion

    @akalineskou It you're interested, please help us verify the fix I submitted. These kinds of errors are practically impossible to catch with automated tests.

  12. scottasmith commented on Jan 10, 2023

    @scottasmith

    I'm also seeing this issue in the below PHP version in Docker based on the php:8.2-fpm image on an AWS/ARM64 container.

    root@9836b6512b0c:/var/www/app# php -v
    PHP 8.2.1 (cli) (built: Jan  5 2023 23:29:35) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.2.1, Copyright (c) Zend Technologies
        with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies
    
  13. drekinov commented on Jan 11, 2023

    @drekinov

    We get same issue from PHP 8.2.1, Ubuntu 22.04, AWS/Ec2/Graviton2/ARMs.
    It is affecting only some requests. Most are fine (fortunately) because we are all in on production :)
    All apps are Symfony 6.2.x and php config is failry simple:

    php_value[opcache.file_cache]  = NULL
    php_value[opcache.file_cache_only] = 0
    php_value[opcache.enable] = 1
    php_value[opcache.enable_cli] = 0
    php_value[opcache.save_comments] = 1
    php_value[opcache.fast_shutdown] = 0
    php_value[opcache.revalidate_freq] = 60
    php_value[opcache.memory_consumption] = 128
    php_value[opcache.interned_strings_buffer] = 16
    php_value[opcache.max_accelerated_files] = 30000
    php_value[opcache.validate_timestamps] = 0
    php_value[opcache.jit_buffer_size] = 128
    php_value[realpath_cache_size] = 4096K
    php_value[realpath_cache_ttl] = 120
    ; + 
    php_admin_value[open_basedir] 
    
  14. cmb69 commented on Jan 11, 2023

    @cmb69
    Member

    Instead of telling that you are affected by this, too, it would be better to check whether #10143 solves the problem. :)

  15. scottasmith commented on Jan 11, 2023

    @scottasmith

    Instead of telling that you are affected by this, too, it would be better to check whether #10143 solves the problem. :)

    I would absolutely love to compile with the patch and test but I can never seem to replicate the issue. I had a go last night on a testbed.
    If someone can pinpoint how it occurs then I would be happy to test with/without the patch :)

  16. tomocrafter commented on Jan 14, 2023

    @tomocrafter

    I'm in the same boat with laravel

    • laravel/framework v8.83.27
    • php 8.2.1

    This bug is difficult to reproduce, but certainly occurs unpredictable and rare in real-world applications.

  17. ziming commented on Jan 14, 2023

    @ziming

    it happen for me quite often in laravel nova on php 8.2 with op cache on

  18. added 2 commits that reference this issue on Jan 16, 2023
    db63474
    e560592
  19. ssx commented on Jan 17, 2023

    @ssx
  20. josefbenjac commented on Jan 17, 2023

    @josefbenjac

    Error is still happening, update to 8.2.1 did not help. It happens quite often but randomly it even passes.

  21. spideyfusion commented on Jan 17, 2023

    @spideyfusion

    @josefbenjac The fix was just merged yesterday and will be bundled with PHP 8.2.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions