Warning: array offset on float in class-evaluate-phpspreadsheet.php (fix include
-
Hi,
I’m using the latest version of TablePress and encountered repeated warnings in the PHP-FPM/Nginx error log:
PHP Warning: Trying to access array offset on float in /wp-content/plugins/tablepress/classes/class-evaluate-phpspreadsheet.php on line 49
It occurs during formula evaluation inside:
TablePress_Evaluate_PHPSpreadsheet::evaluate_table_data()
Specifically, at this line:
if ( '' === $cell_content || '=' === $cell_content || '=' !== $cell_content[0] ) {When
$cell_contentis a float or integer (not a string), accessing$cell_content[0]causes:Trying to access array offset on floatThis happened because my plugin populates the table with numeric values (floats/ints), not only strings.
============Temporary Fix That Resolved It============
Before the condition, I added an explicit cast:
$cell_content = (string) $cell_content;This avoids the warning entirely and everything works normally. Additional Context
I also noticed high CPU usage around the same time, but I can’t confirm that this warning is directly responsible. Mentioning it only because the error log was filled with thousands of these warnings.
============Environment============
- Block Theme: no
- TablePress: 3.2.5
- TablePress (DB): 119
- TablePress table scheme: 3
- Plan: Free
- Plugin installed: 2024/04/16 14:04:50
- WordPress: 6.8.3
- Multisite: no
- PHP: 8.3.10
- mySQL (Server): 10.5.25-MariaDB
- mySQL (Client): mysqlnd 8.3.10
- mbstring: yes
- ZipArchive: no
- DOMDocument: yes
- simplexml_load_string: yes
- libxml_disable_entity_loader: yes
- UTF-8 conversion: yes
- WP Memory Limit: 40M
- Server Memory Limit: 256M
- WP_DEBUG: false
- WP_POST_REVISIONS: true
You must be logged in to reply to this topic.