Elgg /
Elgg
implicit conversion of array to boolean.
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * |
||
| 4 | */ |
||
| 5 | |||
| 6 | namespace Elgg\Config; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Migrates dataroot database value to settings.php |
||
| 10 | * |
||
| 11 | * @access private |
||
| 12 | */ |
||
| 13 | class DatarootSettingMigrator extends SettingsMigrator { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * {@inheritdoc} |
||
| 17 | */ |
||
| 18 | 1 | public function migrate() { |
|
| 19 | |||
| 20 | try { |
||
| 21 | 1 | $row = $this->db->getDataRow(" |
|
| 22 | 1 | SELECT value FROM {$this->db->prefix}datalists |
|
| 23 | WHERE name = 'dataroot' |
||
| 24 | "); |
||
| 25 | |||
| 26 | 1 | if ($row) { |
|
|
0 ignored issues
–
show
|
|||
| 27 | 1 | $value = $row->value; |
|
| 28 | $lines = [ |
||
| 29 | 1 | "", |
|
| 30 | 1 | "/**", |
|
| 31 | 1 | " * The full file path for Elgg data storage. E.g. /path/to/elgg-data/", |
|
| 32 | 1 | " *", |
|
| 33 | 1 | " * @global string \$CONFIG->dataroot", |
|
| 34 | 1 | " */", |
|
| 35 | 1 | "\$CONFIG->dataroot = \"{$value}\";", |
|
| 36 | 1 | "" |
|
| 37 | ]; |
||
| 38 | 1 | $bytes = implode(PHP_EOL, $lines); |
|
| 39 | |||
| 40 | 1 | $this->append($bytes); |
|
| 41 | |||
| 42 | 1 | return $value; |
|
| 43 | } else { |
||
| 44 | error_log("The DB table {$this->db->prefix}datalists did not have 'dataroot'."); |
||
| 45 | } |
||
| 46 | } catch (\DatabaseException $ex) { |
||
| 47 | error_log($ex->getMessage()); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.