CComponent::evaluateExpression enh/bug #1053

Closed
Ekstazi opened this Issue Jul 28, 2012 · 7 comments

Comments

3 participants
Contributor

Ekstazi commented Jul 28, 2012

I try to do like this:

// also if $func='max'
$func=max;
            $max = $this->evaluateExpression($func,array(
                'arg1'=>$max,
                'arg2'=>$node->getEav($eavName, $eavDefault),
            ));

But evaluateExpression didn't check if the is valid callback and evalute it as php expression.

Think that way to check for is_callable in CComponent::evaluateExpression:

        if(is_callable($_expression_))
        {
            $_data_[]=$this;
            return call_user_func_array($_expression_, $_data_);
        }else 
        {
            extract($_data_);
            return eval('return '.$_expression_.';');
        }
Owner

samdark commented Jul 28, 2012

evaluateExpression accepts both strings and callbacks by design.

Contributor

Ekstazi commented Jul 28, 2012

Something wrong ? If $expression is not callable then it is the string:

    if(is_callable($_expression_))
        {
            $_data_[]=$this;
            return call_user_func_array($_expression_, $_data_);
        }elseif(is_string($_expression_)) 
        {
            extract($_data_);
            return eval('return '.$_expression_.';');
        }

samdark was assigned Jul 28, 2012

Owner

samdark commented Jul 28, 2012

There are valid use-cases for it. Support this change. It will allow using global functions as callbacks.

@Ekstazi Ekstazi added a commit to Ekstazi/yii that referenced this issue Jul 29, 2012

@Ekstazi Ekstazi Enh #1053: CComponent::evaluateExpression allow using global function…
…s as callbacks
b5fe088

@Ekstazi Ekstazi added a commit to Ekstazi/yii that referenced this issue Jul 29, 2012

@Ekstazi Ekstazi Enh #1053: CComponent::evaluateExpression allow using global function…
…s as callbacks fixed
1cbbebd
Member

mdomba commented Jul 29, 2012

Why 2 PR ?

Contributor

Ekstazi commented Jul 29, 2012

Sorry, i first day work with git.

Member

mdomba commented Jul 29, 2012

No problem... so the first one can be closed?

Contributor

Ekstazi commented Jul 29, 2012

Yes

@Ekstazi Ekstazi added a commit to Ekstazi/yii that referenced this issue Jul 29, 2012

@Ekstazi Ekstazi Enh #1053: CComponent::evaluateExpression allow using global function…
…s as callbacks fixed 2
3af0e26

@samdark samdark added a commit that referenced this issue Jul 29, 2012

@samdark samdark Merge pull request #1061 from Ekstazi/1053-CComponent-evaluateExpress…
…ion-enh-fixed

Enh #1053 CComponent::evaluateExpression enh fixed
5092d42

samdark closed this Jul 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment