Skip to content

Viewport lazy-load CSS crashes when profile data contains stdClass #1105

Description

@pirate-bot

Summary

Generating personalized background lazy-load CSS can terminate a frontend response when stored per-device profile data is an object rather than the expected array. The CSS generation path is expected to tolerate unavailable or malformed profile data and continue rendering. Instead, it raises Cannot use object of type stdClass as array, preventing the response from completing for the affected request.

Customer context

  • Product / area: Optimole viewport lazy loading and personalized background CSS
  • Version: 4.2.10
  • Environment: WordPress 7.0.2; PHP 8.3.17 and 8.3.31
  • Integration / third party: A Nextend Smart Slider output-buffer frame appears in the captured stack, but the exception location is Optimole code.
  • Reported error / symptom: Error: Cannot use object of type stdClass as array during a frontend request
  • Impact: Telemetry recorded 2 occurrences across 2 sites between 2026-08-02 and 2026-08-05.

Reproduction notes

  1. Enable viewport lazy loading so frontend output reaches personalized background CSS generation.
  2. Load current profile data with a mobile or desktop device payload represented as stdClass instead of the documented associative array.
  3. Render a non-partial frontend response.

Observed production result: the request raises Cannot use object of type stdClass as array at the personalized CSS generation step. The telemetry does not include the profile payload that led to the object value.

Diagnosis

Conclusion

Production telemetry identifies inc/v2/BgOptimizer/Lazyload.php:37 as the exception location. The inspected 4.2.10 code indexes each per-device profile payload as an array without verifying its runtime type. A local PHP 8.3 check of the equivalent expression with a stdClass payload produces the reported fatal error. This confirms the crash behavior when malformed object-shaped profile data reaches this path.

Where this likely occurs

  • inc/manager.phpOptml_Manager::replace_content() lines 495-501 invokes Lazyload::get_current_personalized_css() for non-partial frontend output when viewport lazy loading is enabled.
  • inc/v2/BgOptimizer/Lazyload.phpLazyload::get_current_personalized_css() lines 21-22 passes the current profile data into the CSS generator.
  • inc/v2/BgOptimizer/Lazyload.phpLazyload::get_personalized_css() lines 31-38 accesses $data[$device]['bg'] and $data[$device]['lcp']; a stdClass value at a device key produces the telemetry error at line 37.
  • inc/v2/PageProfiler/Profile.phpProfile::set_current_profile_data() lines 336-352 places raw storage results for mobile and desktop into the current profile array without a runtime shape check.
  • The array-offset path was introduced by commit 6830ea91e and is present from tag v4.0.0 through inspected tag v4.2.10.

Engineering notes

  • Profile::store() writes the expected per-device associative-array shape in inc/v2/PageProfiler/Profile.php lines 183-218.
  • Profile selects its backing storage through the optml_page_profiler_storage filter in inc/v2/PageProfiler/Profile.php lines 89-105. The built-in transient reader returns mixed in inc/v2/PageProfiler/Storage/Transients.php lines 64-72, so the current-profile load boundary has no enforced array contract.
  • The telemetry stack establishes the frontend path and error location. It does not identify how the affected object-shaped value entered storage. The Nextend frame closes output buffers after the Optimole call and does not establish that Nextend created the malformed profile value.

Test coverage status

tests/test-lazyload-viewport.phptest_profile_data_storage_and_retrieval() lines 211-247 covers normal array-shaped profile storage and retrieval. No direct tests for Lazyload::get_personalized_css(), Lazyload::get_current_personalized_css(), malformed per-device profile data, or the background-CSS marker were found during inspection.

What to verify or explore next

  • Reproduce the frontend viewport-lazy-load workflow with one mobile or desktop profile storage value represented as stdClass.
  • Run the relevant viewport lazy-load suite, including tests/test-lazyload-viewport.php, after exercising the personalized CSS branch.
  • Check whether persistent object-cache implementations, profile-storage filters, or migrated profile values can return object-shaped data for this storage key.

Unknowns / follow-up

  • The source of the object-shaped profile value is unknown from the telemetry and inspected repository code.
  • The affected sites' object-cache configuration, profile-storage filter usage, and stored profile values were not available.

Confidence

Confidence: 96/100

Production telemetry records the exact frontend exception at the same array-offset expression present in the inspected 4.2.10 source; a local PHP check confirms that expression throws when a per-device profile value is stdClass.

Crash telemetry

Occurrences 2
Distinct sites 2
First seen 2026-08-02 11:48 UTC
Last seen 2026-08-05 14:13 UTC
Crash location product:inc/v2/BgOptimizer/Lazyload.php:37
Request context frontend
Inside Themeisle SDK no
Product versions 4.2.10
WP versions 7.0.2
PHP versions 8.3.17, 8.3.31
SDK versions 3.3.58

Source: automated crash report — optimole-wp, fingerprint f86795f5fedc77801fff1ed1af50b8e4
Generated by bug-report-triage (ID: bug-report-triage_6a76c5ff5e3406.21193513)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions