php-src icon indicating copy to clipboard operation
php-src copied to clipboard

Method visibility issue introduced in version 8.3.8

Open aurimasrim opened this issue 2 years ago • 19 comments

Description

The following code:

<?php

trait PropertyHelperTrait
{
    protected function splitPropertyParts(): void
    {
    }
}

trait OrmPropertyHelperTrait
{
    abstract protected function splitPropertyParts(): void;
    
    protected function addJoinsForNestedProperty(): void
    {
        $this->splitPropertyParts();
    }
}

trait SearchFilterTrait
{
    use PropertyHelperTrait;
}

abstract class AbstractFilter
{
    use OrmPropertyHelperTrait, PropertyHelperTrait;
    
    public function apply(): void
    {
        $this->filterProperty();
    }
    
    abstract protected function filterProperty(): void;
}

class SearchFilter extends AbstractFilter
{
    use SearchFilterTrait;
    protected function filterProperty(): void
    {
        $this->addJoinsForNestedProperty();
    }
}

class FilterExtension
{
    public function applyToCollection(): void
    {
        (new SearchFilter())->apply();
    }
}

(new FilterExtension)->applyToCollection();

Resulted in this output:

Fatal error: Uncaught Error: Call to protected method SearchFilter::splitPropertyParts() from scope AbstractFilter in /in/ZsLJ0:16
Stack trace:
#0 /in/ZsLJ0(42): AbstractFilter->addJoinsForNestedProperty()
#1 /in/ZsLJ0(31): SearchFilter->filterProperty()
#2 /in/ZsLJ0(50): AbstractFilter->apply()
#3 /in/ZsLJ0(54): FilterExtension->applyToCollection()
#4 {main}
  thrown in /in/ZsLJ0 on line 16

But I expected this output instead: It should produce no errors

More info: Our CI started to fail today without changes from our side. It uses the latest PHP patch version which now is 8.3.8. This code succeeds in PHP 8.3.7 It can be reproduced here The code is a simplified piece of code from a popular PHP framework API platform

PHP Version

PHP 8.3.8

Operating System

Ubuntu 22.04

aurimasrim avatar Jun 05 '24 11:06 aurimasrim

probably related with #14148 and #14152 changes

mvorisek avatar Jun 05 '24 12:06 mvorisek

/cc @dstogov It seems this was indeed introduced in GH-14152 / GH-14148.

ndossche avatar Jun 05 '24 15:06 ndossche

This also impacts PHP 8.2.20

jamesisaac avatar Jun 05 '24 15:06 jamesisaac

Will this fix be released only in the next patch version 8.3.9?

aurimasrim avatar Jun 06 '24 07:06 aurimasrim

Will this fix be released only in the next patch version 8.3.9?

It can't be released before 8.3.9

@bukka ^^

dstogov avatar Jun 06 '24 08:06 dstogov

Will this fix be released only in the next patch version 8.3.9?

It can't be released before 8.3.9

@bukka ^^

@dstogov so this means that 8.3.8 is unstable to use in production and we should avoid updating it, right?

rmikalkenas avatar Jun 06 '24 10:06 rmikalkenas

@dstogov so this means that 8.3.8 is unstable to use in production and we should avoid updating it, right?

In case you affected by this bug, you may skip 8.3.8 or rebuild it including the fix.

dstogov avatar Jun 06 '24 10:06 dstogov

Problem is big if you use 3rd party Linux repository which deletes older packages, like Ondrej's PPA. If you build PHP now and use that repo, you have to use 8.2.20, because it's not possible to get older version from there, you will run into errors like these

E: Failed to fetch https://ppa.launchpadcontent.net/ondrej/php/ubuntu/pool/main/p/php8.2/php8.2-sqlite3_8.2.19-2%2bubuntu22.04.1%2bdeb.sury.org%2b1_amd64.deb  404  Not Found [IP: 185.125.190.80 443]

edit: Looks like Ondrej reacted to my e-mail inquiry (even though not responded) and created new 8.2.20-2 which includes this patch!

ostrolucky avatar Jun 08 '24 17:06 ostrolucky

When will php 8.3.9 be released?

sasa1007 avatar Jun 19 '24 08:06 sasa1007

Same issue here, we are using API Platform. Big impact in production on a PaaS hosting so no possibility to downgrade to a minor version. Very blocking.

axeloz avatar Jun 28 '24 08:06 axeloz

Worth noting that this issue can result in SIGSEGV instead of just a visibility error, or at least in our case it did.

tfp-rv avatar Jul 02 '24 10:07 tfp-rv

Same issue here, we are using API Platform. Big impact in production on a PaaS hosting so no possibility to downgrade to a minor version. Very blocking.

If you are using Azure webapp on Linux, you can use app setting WEBSITE_PIN_RUNTIME_IMAGE with value appsvc/php:8.2-fpm_20240522.2.tuxprod It targets PHP 8.2.17

sebastienjuglar avatar Jul 17 '24 16:07 sebastienjuglar

Worth noting that this issue can result in SIGSEGV instead of just a visibility error, or at least in our case it did.

Indeed. And it seems to still trigger on 8.3.10. We are using the ZTS SAPI and on some occasions it still triggers the error message and sometimes quits with a SIGSEGV. Unfortunately i cannot reproduce it reliably yet. I will downgrade to 3.8.7 and see if the issue does not happen.

This is the stacktrace we are seeing for the crash: image

8.3.7 is working perfectly.

paresy avatar Aug 15 '24 09:08 paresy

If it crashes at line 1308, then that means that fbc_scope is an invalid pointer. Can you do bt full instead of bt ? Ideally, we do get a reproducer though.

ndossche avatar Aug 21 '24 20:08 ndossche

This is still hitting us in 8.4.4. I am trying to get a reproducer, but until then i have a "bt full" output

@nielsdos

(gdb) bt full
#0  zend_check_protected (ce=0x8200000400000002, scope=0x41698ff0) at Zend/zend_object_handlers.c:1578
        fbc_scope = 0x8200000400000002
#1  zend_std_get_method (obj_ptr=<optimized out>, method_name=0x4024ab98, key=0x41697a18) at Zend/zend_object_handlers.c:1816
        zobj = 0x7fff53657188
        lc_method_name = 0x4024ab70
        use_heap = <optimized out>
        func = <optimized out>
        fbc = 0x41691688
        scope = 0x41698ff0
#2  0x000055555829b72a in ZEND_INIT_METHOD_CALL_SPEC_UNUSED_CONST_HANDLER (execute_data=0x7fff53612001) at Zend/zend_vm_execute.h:34964
        orig_obj = 0x41698ff0
        opline = 0x41691688
        object = 0x7fff53612021
        obj = 0x7fff53657188
        called_scope = 0x4024ab98
        fbc = <optimized out>
        call_info = <optimized out>
        call = <optimized out>
        function_name = <optimized out>
#3  0x00007fff536120c0 in ?? ()
No symbol table info available.
#4  0xffffffffffffffb8 in ?? ()
No symbol table info available.
#5  0x0000000000130000 in ?? ()
No symbol table info available.
#6  0xffffffffffffffb8 in ?? ()
No symbol table info available.
#7  0x000055555a231038 in ?? ()
No symbol table info available.
#8  0x00007fff8f3fb580 in ?? ()
No symbol table info available.
#9  0x000055555826c518 in execute_ex (ex=<optimized out>) at Zend/zend_vm_execute.h:58584
        ret = <optimized out>
        execute_data = <optimized out>

paresy avatar Apr 09 '25 11:04 paresy

In our use-case it seems to stop, when the we disable the OpCache. The code, that is triggering the crash, will not trigger the crash per se. It seems like something else needs to corrupt the OpCache first, and then this will trigger the warning and crash.

paresy avatar Apr 09 '25 18:04 paresy

The ce address in your stacktrace is nonsensical, so indeed something has corrupted that. It's hard to know for sure what that is. The problem with backtraces is that they show the point of the crash, not the point where it initially started to go wrong and started corrupting :/ If you have a reproducer, or maybe even small project, or at least something that reproduces the crash (doesn't even have to reproduce consistently) then I can have a look and try to debug this. If you can't share code, then you could try to build a debug PHP build yourself and run the project under that build; if that's within the possibilities.

ndossche avatar Apr 09 '25 18:04 ndossche

At the moment i can't really trigger the crash properly. It is a big project and i want to break it down to a small reporducer. At least for the moment it seems that we need two steps to trigger it. Do you have any hints on how to debug OpCache corruption?

paresy avatar Apr 09 '25 18:04 paresy

If you want to make it more reliable, set the ini option opcache.protect_memory=1; also set opcache.log_verbosity_level=3. Can't do much more using INI settings

ndossche avatar Apr 09 '25 18:04 ndossche