Troubles with deployment the project

Hi!

Today I decide to upload my project in hosting for test some possible bugs. But what I forgot to do is to compare the php vesions in local server and hosting. It’s 5.2 in hosting and 5.3 in local. So the majority of my classes doesn’t works at all.

The reason is that I use such style in my methods:


class Media extends CComponent

{


	public function Listing($mo, $crit = array(), $paging = 0)

	{


        $criterion = new CDbCriteria;

        $criterion->order = 'id DESC';


        // Additional criterion

        foreach ( $crit as $k => $v ) {

            $criterion->$k = $v;

        }


        // Enable pagination

        if ( $paging > 0 ) {


    		$qnt = $mo::model()->count($criterion);


    		$pages = new CPagination($qnt);

    		$pages->pageSize = $paging;

    		$pages->applyLimit($criterion);


        }


        $model = $mo::model()->findAll($criterion);


	return array(

            'model' => $model,

            'pages' => $pages,

        );


	}

	

	...

}

It’s slice of one class. The method Listing is for helping to display the data. I pass the model name in variable $mo. So the construction $mo::model() doesn’t works in 5.2 ( exception t_paamayim_nekudotayim ).

Should I repeat the same slice of code for each of five models, and only difference is the class name? I just think nobody except me does not write the code with such style :unsure:

Do you maybe know the way I can replace this stuff with more readable and flexible code?

I know it may has no relation to yii, but I don’t know what if yii has some resolution in this case.

You can use call_user_func().

Thanks Mike. I just found one more workaround ( not sure if it is workaround at all ):


$mdl = new $mo();

$qnt = $mdl->model()->count($criterion);

instead of:


$qnt = $mo::model()->count($criterion);

And it works fine in 5.2. I don’t know how it may affect on performance, but I hope it doesn’t at all.

In essence this is even more problematic:

  1. you create an object where you don’t have to

  2. you call a static method (class context) like a usual method (object context)

  3. means, you are wasting resources, 2. means, you depend even more on PHP to allow this incorrect call of a static method (could be changed in later versions).

Okay. Could you please show an example. Because I dont really understood how replace my code with call_user_func :(

Uhm, you did read the docs, did you? :)


mixed call_user_func ( callback $function [, mixed $parameter [, mixed $... ]] )

So how about:


call_user_func(array($mo,'model'))->findAll($criterion);

// Or if you want to reuse the return value of model():

$mod=call_user_func(array($mo,'model'));

$qnt=$mod->count($criterion)

$model=$mod->findAll($criterion)