Yii2: Random crash: Undefined offset: 1 in log Target

Created on 3 Nov 2017  路  4Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

Fastest way is to turn on profiling.

A value from microtime(true) call does not always contain usec part. So the expression list($timestamp, $usec) = explode('.', StringHelper::floatToString($timestamp)); will trigger PHP error in such cases.

What is the expected result?

Application should not crash.

What do you get instead?

PHP Error[8]: Undefined offset: 1
    in file /opt/lpp/vendor/yiisoft/yii2/log/Target.php at line 363
#0 /opt/lpp/vendor/yiisoft/yii2/log/Target.php(280): yii\log\FileTarget->getTime()
#1 unknown(0): yii\log\FileTarget->formatMessage()
#2 /opt/lpp/vendor/yiisoft/yii2/log/FileTarget.php(106): array_map()
#3 /opt/lpp/vendor/yiisoft/yii2/log/Target.php(129): yii\log\FileTarget->export()
#4 /opt/lpp/vendor/yiisoft/yii2/log/Dispatcher.php(189): yii\log\FileTarget->collect()
#5 /opt/lpp/vendor/yiisoft/yii2/log/Logger.php(177): yii\log\Dispatcher->dispatch()

Additional info

| Q | A
| ---------------- | ---
| Yii version | 2.0.13
| PHP version | 7.0.25
| Operating system | Ubuntu

bug

All 4 comments

in which case does microtime not contain mircoseconds?

I suppose when microseconds equal to zero then value returned without floating part.

while (true) list($a, $b) = explode('.', (string)microtime(true));

This will trigger the error for sure :)

@ischenko thanks, would you like to send a pull request to fix this?

Was this page helpful?
0 / 5 - 0 ratings