Skip to content

Cannot access protected property Page::$title in Cascade::jsonLd() breadcrumbs #512

@jimblue

Description

@jimblue

Bug Description

Cascade::jsonLd() accesses $crumb->title as a property at line 601 of src/Cascade.php:

$breadcrumbs->map(function ($crumb, $index) {
    return [
        '@type' => 'ListItem',
        'position' => $index,
        'name' => $crumb->title,  // ← accesses protected property directly
        'item' => $crumb->absoluteUrl(),
    ];
})

Statamic\Structures\Page::$title is a protected property. In a normal front-end rendering context, the HasAugmentedInstance::__get() magic method intercepts the property access and it works fine. However, when an Entry is serialized from a different context — specifically via json_encode() triggered by Laravel Telescope's ExtractProperties — the __get() interception doesn't apply and PHP throws:

Error: Cannot access protected property Statamic\Structures\Page::$title

Call chain that triggers the bug

  1. Telescope's ExtractProperties::from() calls json_encode() on a Statamic Entry object
  2. Entry implements JsonSerializable → calls toArray()toEvaluatedAugmentedArray()
  3. This augments the seo field, which triggers SEO Pro's Cascade::get()Cascade::jsonLd()
  4. jsonLd() fetches breadcrumbs via Statamic::tag('nav:breadcrumbs')->fetch()
  5. The resulting Page objects have $title as a protected property, causing the error

How to Reproduce

  1. Install Laravel Telescope in a Statamic application with SEO Pro
  2. Enable json_ld_breadcrumbs: true in resources/addons/seo-pro.yaml
  3. Visit any page with breadcrumbs (i.e. any page beyond the homepage)
  4. The error is thrown/logged on every such request

Suggested Fix

Change $crumb->title to $crumb->title() on line 601 of src/Cascade.php, calling the public method instead of relying on __get():

- 'name' => $crumb->title,
+ 'name' => $crumb->title(),

Environment

  • Statamic: v6.5.0
  • SEO Pro: v7.1.1
  • Laravel: v12
  • PHP: 8.5.3
  • Telescope: 5.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions