-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Undefined Array Key with a Key as a Long String #13279
Comments
I don't see this warning. How are you running this code? Just in a CLI script? |
I've attempted to simplify the PHP contained within a large script and may have failed in the process. I think I missed something with the array... |
The example code is a simplified version of a WordPress plugin. It's really odd how array values can't be accessed by the keys here, yet they do exist. It is covered in a forum post at: WordPress.org. This is only in PHP 8.3, not 8.2, In the meantime, I will try to create a simple version so you can replicate it. |
The mbstring extension has changed. I bet that's it. |
@SVGAnimate I think you're on to something. The actual array does contain emoticons and more besides. I am still attempting to create the "simple" version using the review data from the WordPress plugin. |
In the index.php i see suspicius code : uksort($this->reviews_filtered, function ($b, $a)
{
if ($this->review_sort_option == 'review_characters_asc' || $this->review_sort_option == 'review_characters_desc')
{
return mb_strlen($this->reviews_filtered[$a][$this->review_sort_options[$this->review_sort_option]['field']]) - mb_strlen($this->reviews_filtered[$b][$this->review_sort_options[$this->review_sort_option]['field']]);
}
The problem is that in the PHP-8.3 version the mbstring extension filters UTF8 string. Post-Edit: ... @alexdowad can you enlighten us ? I also suspect this bug report. But without more information it is difficult to say more. |
If this is a multibyte issue, I will need more time to isolate the issue and produce a fix in my code. However, whatever is in the array, it really should not be failing at this point - the array key check should be unaffected. |
ext-mbstring doesn't affect how array keys are handled. If this is related to mbstring (to which there indeed have been many changes between 8.2 and 8.3) the bug most likely occurs in a different place. |
It is iterating through an array with keys that don't "exist". Even if the fault occurred before in the code, how is this possible? This is why I reported it as a bug - it's failing either too late or, in based on the code, why is it even failing at all? I will try to recreate this using a stripped back example - but the version in the WordPress plugin does return warnings (version 4.27 as I will add a work-around soon; it will probably need the completed setup). |
I think this would be possible if the string is placed in the wrong bucket, i.e. if it was originally saved in one bucket and then the string+hash change. I suppose this could happen if there was a refcounting bug where the string is modified in-place. But let's wait for your reproducer. |
Got it! Here is the simplified example:
I did try this with some multi-byte characters and emoticons, but this didn't affect the outcome. |
On PHP 8.3.1 i do not have Notice/Warning |
With PHP 8.3.2, here are the log entries:
|
The array isn't just observable if the array has RCn, but also if it is inside a reference that is RCn. By-ref parameters are always RCn and as such always observable. Fixes phpGH-13279
Description
The following code:
Resulted in this output:
But I expected this output instead:
No warnings/errors, just a freshly sorted array.
I have tested the following:
PHP Version
PHP 8.3
Operating System
CentOS 7.9
The text was updated successfully, but these errors were encountered: