PHP - Declare function in class based on condition
Is there a way to do something like this:
class Test {
if(!empty($somevariable)) {
public function somefunction() {
}
}
}
I know this might not be best practice, but I need to do this for a very
specific problem I have, so is there anyway to do it?
I just want that function to be included in the class if that variable
(which is tied to a URL param) is not empty. As it is written now, I get
Error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION
Thanks!
No comments:
Post a Comment