Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix collection get() and at() methods

The get() and at() methods for collections were missing a cast from
TypedValue* to CVarRef, causing them to return true or false instead of
returning the value. Fix that.
  • Loading branch information...
commit 86cc9c8a5e799dec906fcc32c88e7c3030e2072a 1 parent de32d52
@paroski paroski authored joelpob committed
Showing with 35 additions and 10 deletions.
  1. +10 −10 src/runtime/ext/ext_collection.cpp
  2. +25 −0 src/test/test_code_run.cpp
View
20 src/runtime/ext/ext_collection.cpp
@@ -179,7 +179,7 @@ int64 c_Vector::t_count() {
Variant c_Vector::t_at(CVarRef key) {
if (key.isInteger()) {
- return at(key.toInt64());
+ return tvAsCVarRef(at(key.toInt64()));
}
throwBadKeyType();
return null;
@@ -187,7 +187,7 @@ Variant c_Vector::t_at(CVarRef key) {
Variant c_Vector::t_get(CVarRef key) {
if (key.isInteger()) {
- return get(key.toInt64());
+ return tvAsCVarRef(get(key.toInt64()));
}
throwBadKeyType();
return null;
@@ -687,9 +687,9 @@ int64 c_Map::t_count() {
Variant c_Map::t_at(CVarRef key) {
if (key.isInteger()) {
- return at(key.toInt64());
+ return tvAsCVarRef(at(key.toInt64()));
} else if (key.isString()) {
- return at(key.getStringData());
+ return tvAsCVarRef(at(key.getStringData()));
}
throwBadKeyType();
return null;
@@ -697,9 +697,9 @@ Variant c_Map::t_at(CVarRef key) {
Variant c_Map::t_get(CVarRef key) {
if (key.isInteger()) {
- return get(key.toInt64());
+ return tvAsCVarRef(get(key.toInt64()));
} else if (key.isString()) {
- return get(key.getStringData());
+ return tvAsCVarRef(get(key.getStringData()));
}
throwBadKeyType();
return null;
@@ -1542,9 +1542,9 @@ int64 c_StableMap::t_count() {
Variant c_StableMap::t_at(CVarRef key) {
if (key.isInteger()) {
- return at(key.toInt64());
+ return tvAsCVarRef(at(key.toInt64()));
} else if (key.isString()) {
- return at(key.getStringData());
+ return tvAsCVarRef(at(key.getStringData()));
}
throwBadKeyType();
return null;
@@ -1552,9 +1552,9 @@ Variant c_StableMap::t_at(CVarRef key) {
Variant c_StableMap::t_get(CVarRef key) {
if (key.isInteger()) {
- return get(key.toInt64());
+ return tvAsCVarRef(get(key.toInt64()));
} else if (key.isString()) {
- return get(key.getStringData());
+ return tvAsCVarRef(get(key.getStringData()));
}
throwBadKeyType();
return null;
View
25 src/test/test_code_run.cpp
@@ -9093,6 +9093,31 @@ bool TestCodeRun::TestCollectionClasses() {
"string(3) \"bar\"\n"
);
+ MVCRO("<?php\n"
+ "$v = Vector::fromArray(array('foo'));\n"
+ "var_dump($v->at(0));\n"
+ "var_dump($v->get(0));\n"
+ "var_dump($v[0]);\n"
+ "$m = Map::fromArray(array('foo'));\n"
+ "var_dump($m->at(0));\n"
+ "var_dump($m->get(0));\n"
+ "var_dump($m[0]);\n"
+ "$sm = StableMap::fromArray(array('foo'));\n"
+ "var_dump($sm->at(0));\n"
+ "var_dump($sm->get(0));\n"
+ "var_dump($sm[0]);\n"
+ ,
+ "string(3) \"foo\"\n"
+ "string(3) \"foo\"\n"
+ "string(3) \"foo\"\n"
+ "string(3) \"foo\"\n"
+ "string(3) \"foo\"\n"
+ "string(3) \"foo\"\n"
+ "string(3) \"foo\"\n"
+ "string(3) \"foo\"\n"
+ "string(3) \"foo\"\n"
+ );
+
return true;
}
Please sign in to comment.
Something went wrong with that request. Please try again.