Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Special characters in property name of object

Tags:

syntax

php

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.

like image 279
Mark U Avatar asked May 04 '12 20:05

Mark U


People also ask

What are property objects?

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.

Can object property name be number?

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.

What types can be property keys of the object?

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.

What is an object property attribute?

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.


1 Answers

echo $myobject->{'%myproperty'}; 
like image 74
Brad Avatar answered Sep 20 '22 20:09

Brad