Commit 612af2ad by Qiang Xue

Using anonymous function instead of eval for timestamp.

parent be189fc4
......@@ -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();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment