1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 13:47:33 +02:00

HasmMap: fixed empty property name access

Introduced by 3891625cd1

PostgreSQL uses '::' syntax for type casting. Before this fix, HashMap returned ':\xff:' during SQL translation/substitution.
This commit is contained in:
Miloslav Hůla
2017-08-04 14:06:08 +02:00
committed by David Grudl
parent 1b516786fb
commit 0c09ad97ca
2 changed files with 15 additions and 1 deletions

View File

@@ -58,7 +58,7 @@ final class HashMap extends HashMapBase
{
if ($nm == '') {
$nm = "\xFF";
return $this->$nm = $this->$nm ?? $this->getCallback()('');
return isset($this->$nm) ? $this->$nm : $this->$nm = $this->getCallback()('');
} else {
return $this->$nm = $this->getCallback()($nm);
}

14
tests/dibi/HashMap.phpt Normal file
View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
$hash = new Dibi\HashMap(function ($v) {
return "b-$v-e";
});
Assert::same('b-X-e', $hash->{'X'});
Assert::same('b--e', $hash->{''});