T
T
Terion2012-09-11 19:53:01
PHP
Terion, 2012-09-11 19:53:01

Is it possible to overload public (or accessible) properties of an object?

There is an object. Its protected properties are represented as other objects (more precisely, initially they are presented as arrays, and are replaced with objects of the required classes during initialization).
Everything is fine, but I want to do it “lazy”, i.e. so that properties turn into objects only when they are accessed.
For calls from outside, this is easily implemented using the magic __get() method. But it won't work when accessing those properties "from the inside" (i.e. $this->protected_property) because those properties are accessible from the inside.
Is there some clever way to overload the available properties?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bruteo, 2012-09-11
@Terion

You can store data not as separate properties, but as elements of a special array property. And __get() will operate on that array.

A
Alexey Akulovich, 2012-09-12
@AterCattus

You can implement properties as a closure that returns the desired instance. Any DI so implement storage of services.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question