If I have an object that contains a property that starts with a % symbol, how can I get its value.
If I use
echo $myobject->%myproperty;
I get an error
Parse error: syntax error, unexpected '%', expecting T_STRING or T_VARIABLE
I know I shouldn't use % in variable names, but it wasn't my doing and I'm stuck with it.
A property of an object can be explained as a variable that is attached to the object. Object properties are basically the same as ordinary JavaScript variables, except for the attachment to objects. The properties of an object define the characteristics of the object.
According to the official JavaScript documentation you can define object literal property names using integers: Additionally, you can use a numeric or string literal for the name of a property.
Against what many think, JavaScript object keys cannot be Number, Boolean, Null, or Undefined type values. Object keys can only be strings, and even though a developer can use other data types to set an object key, JavaScript automatically converts keys to a string a value.
A distinguishing feature of attributes is that each attribute has its own methods for setting and getting its value. Properties. A property of an object is present and occupies storage only after its value is set. A property cannot be deleted or its storage recovered after its value is set. You can change its value.
echo $myobject->{'%myproperty'};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With