summaryrefslogtreecommitdiff
path: root/tests/cpp/include/ValueIterator.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cpp/include/ValueIterator.h')
-rw-r--r--tests/cpp/include/ValueIterator.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/cpp/include/ValueIterator.h b/tests/cpp/include/ValueIterator.h
index a9329c9..689797a 100644
--- a/tests/cpp/include/ValueIterator.h
+++ b/tests/cpp/include/ValueIterator.h
@@ -19,6 +19,33 @@ namespace TestValueIterator {
}
return;
}
+
+ void loopArray(void)
+ {
+
+ Php::Value value;
+ /*
+ If we fill the array in this form, we get the following:
+ *** Error in `/usr/bin/php': double free or corruption (fasttop): 0x0000000001956d60 ***
+ value[0] = "val0";
+ value[1] = "val1";
+ value["third"] = "val3";
+ value["fourth"] = "val3";
+ */
+ value.set(0 , "val0");
+ value.set(1 , "val1");
+ value.set("third" , "val3");
+ value.set("fourth", "val3");
+
+ std::cout << "Array/Object contains " << value.size() << " items" << std::endl;
+ // assum the value variable holds an array or object, it then
+ // is possible to iterator over the values or properties
+ for (auto &iter : value)
+ {
+ // output key and value
+ Php::out << "["<< iter.first << "]="<< iter.second << std::endl;
+ }
+ }
/**
* End of namespace