phalcon/cphalcon · error · Phalcon\Db\Exceptions\InvalidWkb
Invalid WKB: empty value
Error message
Invalid WKB: empty value
What it means
Phalcon\Db\Geometry\WkbParser::parse() converts WKB/EWKB geometry values from databases into geometry objects. An empty string input is rejected up front with InvalidWkb('empty value') before any parsing, because an empty payload cannot contain a geometry.
Source
Thrown at phalcon/Db/Geometry/WkbParser.zep:42
/**
* @var string
*/
protected buffer = "";
/**
* @var int
*/
protected length = 0;
/**
* @var int
*/
protected position = 0;
public function parse(string raw) -> <GeometryInterface>
{
var srid = 0, body, arr;
if raw === "" {
throw new InvalidWkb("empty value");
}
/**
* PostGIS returns EWKB as an even-length ASCII-hex string; MySQL
* returns binary (4-byte LE SRID prefix + standard WKB). Real binary
* WKB is not valid ASCII hex (it carries the 0x01 byte-order byte and
* arbitrary double bytes), so this distinguishes the two.
*/
if strlen(raw) % 2 === 0 && ctype_xdigit(raw) {
let body = hex2bin(raw);
} else {
if strlen(raw) < 5 {
throw new InvalidWkb("buffer too short for MySQL prefix");
}
let arr = unpack("V", substr(raw, 0, 4)),
srid = (int) arr[1],
body = substr(raw, 4);View on GitHub (pinned to b7419de9cd)
Solutions
- Treat empty/null geometry as null before parsing: if ($value === '' || $value === null) return null;
- Fix the query or schema: filter with WHERE geom IS NOT NULL, or stop storing '' in geometry columns
- Regenerate fixtures with real WKB from ST_AsBinary/ST_AsEWKB
Example fix
// before
$point = $parser->parse($row['geom']);
// after
$point = ($row['geom'] === '' || $row['geom'] === null)
? null
: $parser->parse($row['geom']); Defensive patterns
Strategy: validation
Validate before calling
if (!is_string($raw) || '' === $raw) {
return null; // no geometry on this row
}
return $parser->parse($raw); Type guard
function isNonEmptyWkb(mixed $value): bool
{
return is_string($value) && '' !== $value;
} Try / catch
try {
$geom = $parser->parse($row['geom']);
} catch (\Phalcon\Db\Exceptions\InvalidWkb $e) {
$logger->warning('Unparseable geometry', ['id' => $row['id']]);
$geom = null;
} Prevention
- Filter nullable geometry columns with WHERE geom IS NOT NULL in read queries
- Never store '' in geometry columns — use real NULL
- Generate fixtures with ST_AsBinary so payloads are real WKB
When it happens
Trigger: Feeding $row['geom'] from a nullable geometry column that returned '' instead of NULL; LEFT JOIN rows where the geometry side is missing; fixtures that insert '' as a placeholder geometry.
Common situations: Drivers or ORMs coercing NULL to ''; batch imports over tables with empty-string defaults on geometry columns; test fixtures hand-written without real WKB.
Related errors
- Invalid WKB: buffer too short for MySQL prefix
- Invalid WKB: unknown geometry type {baseType}
- Invalid WKB: truncated buffer
- The expression {type} is unknown
- DATABASE PARAMETER 'FOREIGN_KEY_CHECKS' HAS TO BE 1
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/17a2eeb1d3bb5b72.
Report an issue: GitHub.