When dealing with DOMStringMap, for example when working with data-* attributes, it's possible to use the non-standard get and set functions, that have been added to enhance testability of the library, but also to avoid using dynamic object properties.
The get and set functions are direct mappers to accessing the __get and __set magic methods to set dynamic properties as described in the HTMLElement.dataset documentation.
However, the documentation states the following:
- Multiple words within attributes should be split using hyphens, like
data-example-attribute.
- Multiple words within object properties should be camel-cased, like
dataExampleAttribute.
Camel case properties are automatically corrected to hyphen case, but if they're provided as hyphen case they are not converted back to camel case, which causes issues when doing things like $element->dataset->get("example-attribute"));
When dealing with DOMStringMap, for example when working with
data-*attributes, it's possible to use the non-standardgetandsetfunctions, that have been added to enhance testability of the library, but also to avoid using dynamic object properties.The
getandsetfunctions are direct mappers to accessing the__getand__setmagic methods to set dynamic properties as described in the HTMLElement.dataset documentation.However, the documentation states the following:
data-example-attribute.dataExampleAttribute.Camel case properties are automatically corrected to hyphen case, but if they're provided as hyphen case they are not converted back to camel case, which causes issues when doing things like
$element->dataset->get("example-attribute"));