forrest lyman Fri Jan 28 12:51:59 -0500 2011

Subject: callback scope

I am running into an odd situation which may just be the way that late static binding works with php, but hopefully there is a way around it.

The callback methods seem to work well for single callbacks. I could not figure out how to add a stack of callbacks, but that is easy to get around.

The challenge I am running into is scope with inheritance.

class User extends ActiveRecord\Model{}
class Student extends User {}

The base user model has a before_save callback which handles password and role logic. This works fine within the scope of a user, but when I save a student the callback function is running within the scope of the parent class.

I added this to the callback method for testing:

echo get_called_class();

I then added these lines to my tests

// prints User
$user = new User();
$user->name = 'tester';

// this prints User as well. the callback should be running on the Student instance right?
$student = new Student();
$student->name = 'student';

forrest lyman Fri Jan 28 13:42:35 -0500 2011

I just tried this with the nightly build and it works as expected. Thanks for resolving it!