Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Fix: Array to string conversion in Zend\Log\Writer\Db #7282

Conversation

Martin-P
Copy link
Contributor

Fix for issue #7244 where Zend\Log\Writer\Db can trigger an array to string conversion.

Because the method eventIntoColumn has the same issue as mapEventIntoColumn, I applied the patch to eventIntoColumn as well.

@Martin-P
Copy link
Contributor Author

Please don't merge this yet. I am looking into a better approach for this by changing Zend\Log\Formatter\Db and have it use Zend\Log\Formatter\Base::normalize() which seems to be created for this specific issue (Normalize all non-scalar data types (except null) in a string value).

@Martin-P
Copy link
Contributor Author

Martin-P commented Mar 1, 2015

Nevermind, my other idea won't work, because the formatter is unaware of the database columns and therefore does not know if an array should be converted to string.

continue;
}

$data[$columnMap[$name][$key]] = var_export($subvalue, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be json_encode() instead. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using json_encode() objects are stored as stdClass and not as the original class name and this causes loss of data. I looked at other possibilities too (see this comment #7244 (comment) and the one after that).

var_export() keeps the data readable. If the data needs to be processed further, the method Zend\Log\Formatter\Base::normalize() provides a nice way to do this, but I don't see how I can use that method (see my previous comment #7282 (comment)).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough!

@weierophinney weierophinney added this to the 2.4.0 milestone Mar 10, 2015
weierophinney added a commit that referenced this pull request Mar 10, 2015
…string-conversion

Fix: Array to string conversion in Zend\Log\Writer\Db
weierophinney added a commit that referenced this pull request Mar 10, 2015
@weierophinney
Copy link
Member

Merged to develop for release with 2.4.

@Martin-P Martin-P deleted the hotfix/log-writer-db-array-to-string-conversion branch April 4, 2015 15:24
weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015
…fix/log-writer-db-array-to-string-conversion

Fix: Array to string conversion in Zend\Log\Writer\Db
weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants