The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Threaded View

Mad idea - overload as mini domain language

Hi.

This comes out of an idea to use the overload capability in PHP5 for writing terser, declarative statements. In particular I have been rethinking the mock objects interface to Simpletest. For quite a while I have wanted to define a mock like so...

This should be possible in PHP4, but as soon as I use the overload() within SimpleTest everything breaks. Thus it would have to be introduced in a PHP5 only version .

The main point is that a lot of magic can happen in that mock declaration. This really will be all of the syntax. Compare with the situation now where a generate call has to be made, then the mock created and then an expectation set on it and finally thereturn value is set. I've gone from five lines to two. This way works with dependency injection too.

It can be extended to multiple instances and multiple method calls like so...

PHP Code:

$this->MockDoubler(1)->double->at(1)->expect(13)->give(26);

Basically it has become a declarative language. Within the __get() method there will likely be a bunch of context objects flying around, but that's just implementation. Probably a not too difficult one at that. I've done some experiments and all seems to be well. So much so I'd liketo explore it further.

Now I'm using the domain language to specify types in a database. The $transfer object is the incoming data when the object is instantiated from a finder. The values in brackets are the defaults, the "uk" here. If a class type is given, then it will be a collection of other records.