Bug #70851 [Fbk]: Iteration bug

From: Date: Thu, 05 Nov 2015 09:17:35 +0000
Subject: Bug #70851 [Fbk]: Iteration bug
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197038@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70851&edit=1 ID: 70851 Updated by: requinix@php.net Reported by: ponce dot josue94 at gmail dot com Summary: Iteration bug Status: Feedback Type: Bug Package: *General Issues Operating System: Linux PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Yeah. It works. That's the problem. Check the link I gave. Can't fix whatever bug you're trying to report if you can't show us a SHORT script that demonstrates it. Previous Comments: ------------------------------------------------------------------------ [2015-11-05 08:27:12] zjoclips at gmail dot com Hi, I don't know how modify this test script but is all an php script so you can surround it with php tag and it works. ------------------------------------------------------------------------ [2015-11-04 18:09:43] requinix@php.net Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. https://3v4l.org/vUhFj ------------------------------------------------------------------------ [2015-11-04 11:51:54] ponce dot josue94 at gmail dot com Description: ------------ When you use the variable $row in an for iteration or foreach the last element ech time become the current element and at end of iteration become empty. I think is an issue about the name of variable but nobody knows that, maybe you can introduce a warning in the documentation or resolve this problem Test script: --------------- $jsonString = '{"head":["Vehicle Name","2015-10-05","2015-10-06","2015-10-07","2015-10-08","2015-10-09","2015-10-13","2015-10-15","2015-10-16","2015-10-17","2015-10-18","2015-10-19"],"body":[[["V CLASS","1"],["40","","6","2015-10-05"],["41","prova2_2 prova2_2","2","2015-10-06"],["64","","2","2015-10-07"],["65","","2","2015-10-08"],["66","","2","2015-10-09"],["69","","2","2015-10-13"],["35","","6","2015-10-15"],["36","","6","2015-10-16"],["37","","6","2015-10-17"],["38","","6","2015-10-18"],["39","","6","2015-10-19"]],[["CARAVELLE[AB123CD]","2"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["4","Driver_6 Driver_6","8","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["MAGELYS","5"],["42","driverFront office","54","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-! 09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["NN","12"],["70","Autista 2 driver 2.0","25","2015-10-05"],["","","","2015-10-06"],["71","","6","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["49","prova_3 prova_3","25","2015-10-15"],["","","","2015-10-16"],["48","","25","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["NN","16"],["50","prova asdasd","25","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["E CLASS","17"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["55","","2","2015-10-13"],["57","","2","2015-10-15"],["58","","2","2015-10-16! "],["59","","2","2015-10-17"],["60","","2","2015-10-18"],["61"! ,"","2","2015-10-19"]],[["E CLASS","19"],["","","","2015-10-05"],["51","","3","2015-10-06"],["52","","3","2015-10-07"],["53","","3","2015-10-08"],["54","","3","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["V CLASS","25"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["S CLASS","30"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["VIANO","31"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-! 10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["S CLASS","33"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["SPRINTER","34"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["prova_1","35"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","",! "2015-10-18"],["","","","2015-10-19"]],[["S CLASS","37"],["","","","201! 5-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["CARAVELLE","38"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]]],"total":"15"}'; $json = json_decode($jsonString, true); for($i = 0; $i < count($json["body"]); $i ++){ $row = $json["body"][$i]; echo "$i -> ".$row[0][0]." | ".$json["body"][count($json["body"])-1][0][0]."\n"; } Expected result: ---------------- 0 -> V CLASS | CARAVELLE 1 -> CARAVELLE[AB123CD] | CARAVELLE 2 -> MAGELYS | CARAVELLE 3 -> NN | CARAVELLE 4 -> NN | CARAVELLE 5 -> E CLASS | CARAVELLE 6 -> E CLASS | CARAVELLE 7 -> V CLASS | CARAVELLE 8 -> S CLASS | CARAVELLE 9 -> VIANO | CARAVELLE 10 -> S CLASS | CARAVELLE 11 -> SPRINTER | CARAVELLE 12 -> prova_1 | CARAVELLE 13 -> S CLASS | CARAVELLE 14 -> CARAVELLE | CARAVELLE Actual result: -------------- 0 -> V CLASS | V CLASS 1 -> CARAVELLE[AB123CD] | CARAVELLE[AB123CD] 2 -> MAGELYS | MAGELYS 3 -> NN | NN 4 -> NN | NN 5 -> E CLASS | E CLASS 6 -> E CLASS | E CLASS 7 -> V CLASS | V CLASS 8 -> S CLASS | S CLASS 9 -> VIANO | VIANO 10 -> S CLASS | S CLASS 11 -> SPRINTER | SPRINTER 12 -> prova_1 | prova_1 13 -> S CLASS | S CLASS 14 -> S CLASS | S CLASS ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70851&edit=1

« previous php.bugs (#197038) next »