On Saturday, 4 January 2014 at 19:08:45 UTC, Gary Willoughby
wrote:
In D is it possible to handle accessing class properties that
don't exist, similar to PHP's magic methods?
http://www.php.net/manual/en/language.oop5.overloading.php#object.set
For example, the below class doesn't have the 'x' property:
class T
{
this()
{
this.x = "hello world!";
}
}
Can i handle this in a programmatic way to intercept the
property and deal with it?
Something like this:
class T
{
this()
{
this.x = "hello world!";
}
opMagic(A, B)(A property, B value)
{
// property = "x", value = "hello world!"
}
}
OMG i've just found opDispatch!
http://dlang.org/operatoroverloading.html#Dispatch
Fantastic!