Welcome Guest, Not a member yet? Register   Sign In
Variable function names
#1

[eluser]JonoB[/eluser]
Is it possible to use variables as function names?

Code:
$model = 'Product_model';
$function = 'count_products()';
$this->total_rows = $this->CI->$model->$function;

The model part seems to work fine, but it gets stuck at the $function part and php throws an error.

Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Products::$count_products()
Filename: core/Model.php
Line Number: 50

Is there any way of getting around this?
#2

[eluser]CroNiX[/eluser]
I think it will work if you put the parenthesis after the variable function name, not in the actual variable.
$model = 'Product_model';
$function = 'count_products';

$this->total_rows = $this->CI->$model->$function();

http://php.net/manual/en/functions.varia...ctions.php
#3

[eluser]JonoB[/eluser]
Awesome sauce, thank you for your help!




Theme © iAndrew 2016 - Forum software by © MyBB