Bagisto Hosting

Let’s Read Extended Protected Properties .

Updated 15 June 2026

Overview

In Bagisto, every product type quietly hides a few fields — a virtual product has no weight, and a booking product has no guest checkout option.

Our seller Quick Create form had to hide those same fields per type, so the screen only ever shows the inputs that actually make sense.

The easy way is to hardcode that list and move on. The better way is to Read Extended Protected Properties straight from each product type.

Writing the list ourselves is fragile

The quick fix is to simply list what each type skips:

This works today. But the day Bagisto changes a type, or adds a brand new one, the list is suddenly wrong, and a field shows up where it should not.

Worse, nothing ever warns you about it. The list just sits in our code and slowly drifts out of date with every framework update.

The type already has the list — it is just protected

Each product type already stores this list in a protected $skipAttributes property — readable only inside the class and its children, never from our form.

PHP’s Reflection lets us open the class at runtime, unlock the property with setAccessible, and read its value as if it were public:
Use to read Protected Properties

Now the list lives in exactly one place — the product type itself — and our form simply mirrors it, picking up any change on the very next request.

A few things to keep in mind

Reading a protected property does tie us to an internal detail rather than a public method — a small risk if core ever renames it later.

That is exactly why the try/catch returns an empty list on any failure, so the worst case becomes “show every field,” never a fatal error.

It runs once per request, so the cost is tiny, and it needs no upkeep — but if a clean public method ever appears, prefer that instead.

Final Thought

Reaching in to Read Extended Protected Properties is fine when the value already lives somewhere and a child class owns it.

Guard it with try/catch, keep it to one place, and switch to a public method the day core gives you one.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home