I'm quite new to PHP (coming from a rich C++ background). It's a good language, but I'm missing some of my C++ creature comforts, like structs. So I decided to make something that would act as a struct. I came up with the following:
class Struct
{
public string $Foo;
public string $Bar;
}
This looks great in my opinion. Now I would like to be able to initialize these struct variables in place like how you would be able to do in C++:
Struct Structure{ "One", "Two" }
Yet, to my understanding, the only way to do this in PHP is by creating a custom constructor. One downside to this though is that you'd need to create a custom constructor for every struct you make. I think that you may be able to overcome this issue by using inheritance. But the question is: how? I was thinking of creating a constructor in the base class that can somehow initialize the variables of the derived class, but I'm not entirely sure how I would go about doing that (not to mention if that would be a 'good' solution).
Any help would be appreciated!
stdclassinstance with properties using something like$struct = (object) ['Foo' => 'One', 'Bar' => 'Two'];struct(but the language does not provide any help to prevent using incorrect names for the "fields").