Browse Source

Using anonymous function instead of eval for timestamp.

tags/2.0.0-alpha
Qiang Xue 12 years ago
parent
commit
612af2ad85
  1. 6
      yii/behaviors/AutoTimestamp.php

6
yii/behaviors/AutoTimestamp.php

@ -47,8 +47,8 @@ class AutoTimestamp extends Behavior
*/
public $updateAttribute = 'update_time';
/**
* @var string|Expression The expression that will be used for generating the timestamp.
* This can be either a string representing a PHP expression (e.g. 'time()'),
* @var \Closure|Expression The expression that will be used for generating the timestamp.
* This can be either an anonymous function that returns the timestamp value,
* or an [[Expression]] object representing a DB expression (e.g. `new Expression('NOW()')`).
* If not set, it will use the value of `time()` to fill the attributes.
*/
@ -97,7 +97,7 @@ class AutoTimestamp extends Behavior
if ($this->timestamp instanceof Expression) {
return $this->timestamp;
} elseif ($this->timestamp !== null) {
return eval('return ' . $this->timestamp . ';');
return call_user_func($this->timestamp);
} else {
return time();
}

Loading…
Cancel
Save