Field name contain a space or hyphen

I have created a Field name “Sub-heading”, but when I preview in browser I get a debugger message “Undefined property: Kirby\Cms\Page::$sub”

So I’ve then changed the field name to “Sub heading” and I get the same error message.

But when I use “Subheading” it works fine.

EDIT: “subheading” doesn’t seem to work now either. Strange it works now!

Why is this?

Also when I use PHP in my template to suck in the content, does the field name have to be lowercase? Even though the field name in my content is uppercase (Title:)?

You cannot use hyphens or spaces in field names, see Fields | Kirby CMS

No, doesn’t have to be. Probably makes sense to write them in lowercase, because function names don’t start with capital letters in PHP, so imo it looks weird. But up to you.

Thank you.