Ds\Map do not support mysqli result fetch_object
<?php
$mysql = new mysqli('localhost', 'root', '***', 'test');
$rs = $mysql->query('select * from `mydb` limit 10');
while ($row = $rs->fetch_object('\\Ds\\Map'))
{
print_r($row);
}
output:
PHP Recoverable fatal error: Object of class Ds\Map could not be converted to boolean in /test.php on line 4
<?php
$mysql = new mysqli('localhost', 'root', '***', 'test');
$rs = $mysql->query('select * from `mydb` limit 10');
while (null !== ($row = $rs->fetch_object('\\Ds\\Map')))
{
print_r($row);
var_dump($row->id);
var_dump(isset($row['id']));
}
output:
Ds\Map Object
(
)
string(1) "1"
bool(false)
Ds\Map Object
(
)
string(1) "2"
bool(false)
I believe this is because Ds\Map doesn't use the object's properties table to store the data. I don't see a way to support this, sorry. Could just fetch as array and create map using that data.
@rtheunissen thank you.
If it implement magic method __set($key, $value) can support it, like this php code:
class Ds\Map
{
function __set($key, $value)
{
$this[$key] = $value;
}
}
or Ds\Map implement the ArrayAccess interface. It's my imagine.
I'm not sure if array access would solve this. What you could do is create a class like ResultMap that creates an instance of Ds\Map and gets/sets on that instance using its own __get and __set. That way you can fetch into ResultMap and expose a get() method to return the internal map.
Might be faster to just fetch an array and instantiate a new map with it, will need to benchmark that yourself to see what works best for you.
This might also be related (and fixed) to #62
#62 fixes the boolean cast issue but we still can't fetch into any of the structures.