1

Here is very simplified example:

function getList<Tx>():Vector<Tx> {

    $values = ['1','2','3','4','5'];
    $list = Vector{};

    foreach ($values as $value) {
        $list->add((Tx) $value);
    }

    return $list;
}

For instance I know that $values are numeric, derrived from database fetching results or whatever, but stored as strings. So I want to cast them as int through

Vector<int> $myList = $this->getList<int>();

but

Object casts are unsupported. Try 'if ($var instanceof Tx)' or 'invariant($var instanceof Tx, ...)'. (Naming[2055])

So should I use two functions for different types in this case like getListInt():Vector<int> and getListString():Vector<string> or I do miss something?

ashes999
  • 9,925
  • 16
  • 73
  • 124
wake-up-neo
  • 814
  • 7
  • 9

1 Answers1

-1

Just as a workaround, and not really a hacklang answer, but I would just try to solve that in mysql. Why not casting it directly in the mysql query?

SELECT CONVERT(field_as_string,UNSIGNED INTEGER) AS num FROM table;

Then your list is a list of integers, and you can just add it to a Vector.

Kordi
  • 2,405
  • 1
  • 14
  • 13