View Full Version : variable function and CodeIgniter

06-03-2010, 08:07 PM
I run into problem when I use CodeIgniter. It is difficult to explain so I illustrate by an example.

The following is the code :
class Model{
protected $name;

function Model(){
$this->name=" I am from Model";

function display(){
echo $this->name;

class M1 extends Model {

function M1(){
$this->name = "I am from M1";


class M2 extends Model {
function M2(){
$this->name = "I am from M2";


class Setup{
public $m1;
public $m2;

function __construct(){
$this->m1 = new M1();
$this->m2 = new M2();

//this function doesn't work on quercus but work on standar php
function iwant($model){
//to select $m1 or $m2
$this->$model->display(); // Fatal Error: Call to undefined method Setup::

//this function work fine for quercus and standard php
function dontwant($model){
// to selct $m1 or $m2
$tem = $this->$model;


$s = new Setup();

$s->iwant('m1'); //this will cause error on quercus


I have to modify CodeIgniter in order to make it work.

I don't know it is a bug or a limitation !