Thanks @Cronix, I have now read all replies on the link you attached and I think I've got the answer:
As this reply says:
PDO uses emulated prepared statements by default for all MySQL connections. That's why the php script on my second reply was returning both values as strings, differing from the Eloquent query result.
If I modify the script to this (note the two attributes being set):
$pdo = new PDO('mysql:host='.$dbHost.';dbname='.$dbName, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
var_dump($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION));
$q = $pdo->prepare("SELECT id, decimal_value, double_value FROM tests");
$q->execute();
foreach($q as $row) {
var_dump($row);
}
Now the output is like this:
array(6) {
["id"]=>
int(1)
[0]=>
int(1)
["decimal_value"]=>
string(4) "8.22"
[1]=>
string(4) "8.22"
["double_value"]=>
float(8.22)
[2]=>
float(8.22)
}
Which is the same thing I was having with Eloquent (seems that the queries made from Eloquent have EMULATE_PREPARES as false?). Still, the double value is being casted to a number while the decimal value is not.
Now, reading carefully the sub-answers on the stack overflow thread there is this:
"Note that DECIMAL type will still be sent as string even with this configuration that is done on purpose to prevent the decimal from becoming an unreliable float in PHP."
Which is confirmed by this Bug report.
On why the double value from MySQL can be safely casted into a PHP float, and why a decimal not I won't dive right now, but is someone has some links or types knowledge it would be nice.
I guess the issue is resolved, I've learned something new tonight, thanks everyone!