Skip to content

Commit d6930f9

Browse files
committed
Object encoding no longer counts the object to determine whether it should write a comma after an element, as count() may not be reliable, depending on the object (some objects may not be explicitly countable).
1 parent 2d67339 commit d6930f9

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/JsonStream/Encoder.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,23 @@ private function _encodeList($list)
148148
/**
149149
* Encodes an object or associative array.
150150
*
151-
* @param mixed $list
151+
* @param array|object $object
152152
*/
153-
private function _encodeObject($list)
153+
private function _encodeObject($object)
154154
{
155155
$this->_writeValue('{');
156156

157-
$x = 1;
158-
foreach ($list as $key => $value) {
159-
$this->_encodeScalar((string)$key);
160-
$this->_writeValue(':');
161-
$this->encode($value);
157+
$firstIteration = true;
162158

163-
if ($x < count($list)) {
159+
foreach ($object as $key => $value) {
160+
if (!$firstIteration) {
164161
$this->_writeValue(',');
165162
}
163+
$firstIteration = false;
166164

167-
$x++;
165+
$this->_encodeScalar((string)$key);
166+
$this->_writeValue(':');
167+
$this->encode($value);
168168
}
169169

170170
$this->_writeValue('}');

0 commit comments

Comments
 (0)