Nette\Database\Row and missing columns for normalizeRow in Nette 2.0.11
- tomas.lang
- Member | 53
I think I found a bug in Nette\Database\Row:32 when
normalizeRow
is called. Function normalizeRow
assumes
there exist all columns in $data
array, but for me sometimes
foreach ($this as $key => $value)
doesn't go over all fields.
I don't have a complete test case now, but at least for transcriptions: go
throught 6000 rows with 31 columns, and first error occurs cca on 600. row
(in my case). Sometimes there are 3 columns remaining in $this,
sometimes 29.
I „fixed“ this problem with a change Nette\Database\Row:32 to
foreach ((array) $this as $key => $value)
– i assume this
construction doesn't use getIterator()
of ArrayHash
class, and that fix the problem, but i'm not sure.
Has anyone similar experiences?
I tested it on PHP v. PHP 5.4.13 (cli) (built: Mar 16 2013 13:38:08) and PHP 5.3.26–1~dotdeb.0 with Suhosin-Patch (cli) (built: Jun 9 2013 03:35:34) .
I will try to provide a test case for this situation…
Last edited by tomas.lang (2013-07-23 19:01)
- Majkl578
- Moderator | 1364
I guess it may be caused by modifying the object which is being iterated
(which leads to an undefined behavior). Related commit: https://github.com/…fb6260085566.
I opened an issue for this on GitHub, move the discussion there, please: https://github.com/…/issues/1198
- David Grudl
- Nette Core | 8082
Majkl578: Why modifying of iterated object leads to an undefined behavior?
Kacer_Bob, clonator: could you confirm that tomas.lang's fix works for you?
- Majkl578
- Moderator | 1364
Quoting PHP manual for foreach:
As foreach relies on the internal array pointer changing it within the loop may lead to unexpected behavior.
Can't say it's correct assumption, but since the iterator is treating an
object like an array (RecursiveArrayIterator
), that was the first
idea I got. :)
- David Grudl
- Nette Core | 8082
Foreach iterates over copy of array. This is certainly a PHP bug (maybe opcode cache bug) and the question is, how to isolate it.