Nette\Database\Row and missing columns for normalizeRow in Nette 2.0.11

Notice: This thread is very old.

7 years ago

tomas.lang
Member | 54
+
0
-

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)

7 years ago

Kacer_Bob
Member | 6
+
0
-

I met the same problem and had to revert back to Nette version 2.0.10.
I run exactly the same code multiple times and the problem appeared randomly.

7 years ago

clonator
Member | 3
+
0
-

I have a same problem.

7 years ago

Majkl578
Moderator | 1376
+
0
-

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

7 years ago

David Grudl
Nette Core | 7067
+
0
-

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?

7 years ago

Majkl578
Moderator | 1376
+
0
-

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. :)

7 years ago

David Grudl
Nette Core | 7067
+
0
-

Foreach iterates over copy of array. This is certainly a PHP bug (maybe opcode cache bug) and the question is, how to isolate it.