Create Class functions on the fly?

Posted by JasonS on Stack Overflow See other posts from Stack Overflow or by JasonS
Published on 2010-03-30T11:10:17Z Indexed on 2010/03/30 11:13 UTC
Read the original article Hit count: 476

Filed under:
|

Hi,

i have a validation class which needs improving. If I require some custom validation I need to specify a custom function. It works a bit like this:

  1. The controller tells the validation that a custom validation function is required.
  2. The controller runs the validation.
  3. --- Gets iffy here ---
  4. Validation class creates a new instance of the controller class....
  5. Validation class runs controller->custom_validation_function()
  6. Validation class returns true / false

Is there someway that I can alter this to do something like this?

$validation = new validation; // Insert rules here. $validation->function() = $this->function();

By doing this I could get rid of the step of creating an unneeded class instance.

© Stack Overflow or respective owner

Related posts about php

Related posts about object-oriented-design