Hey I have been reading some PHP class documentation and how to create classes. But I haven't seen any examples of properties inside the properties. I will give an example what I want to do:
class Properties {
public property1;
public nestedProperty1;
public nestedProperty2;
}
and I want to assign properties like this:
$Property = new Properties();
$Property->property1 = "foo";
$property1->nestedProperty1 = "bar";
So I could access data like:
$property1->nestedProperty1;
Is this possible? I need this because I'm working with a dynamic multidimentional array.
1) classes != arrays.
2) You want nested CLASSES.
For example (pseudo code):
// Create a class
MyThingClass {
string ThingProperty1
int ThingProperty2
}
// Create a MyThingClass instance
MyThing = new MyThingClass(...)
// Use instance in another class
MyOtherThingClass {
MyThingClass MyThing
string SomeOtherProperty
}
You cannot nest properties directly like you are trying to do. You could also use structures as properties.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.