{"record":{"id":"dd3b19c01d73fb30","repo":"phalcon/cphalcon","slug":"check-expression-must-be-a-non-empty-string","errorCode":null,"errorMessage":"CHECK expression must be a non-empty string","messagePattern":"CHECK expression must be a non-empty string","errorType":"exception","errorClass":"InvalidCheckExpression","httpStatus":null,"severity":"error","filePath":"phalcon/Db/Check.zep","lineNumber":76,"sourceCode":"     * prefix in that case.\n     *\n     * @var string\n     */\n    protected name;\n\n    /**\n     * Phalcon\\Db\\Check constructor\n     */\n    public function __construct( string name,  array definition)\n    {\n        var expression;\n\n        if unlikely !fetch expression, definition[\"expression\"] {\n            throw new CheckExpressionRequired();\n        }\n\n        if unlikely typeof expression != \"string\" || expression === \"\" {\n            throw new InvalidCheckExpression();\n        }\n\n        let this->name       = name;\n        let this->expression = expression;\n    }\n\n    /**\n     * Returns the CHECK expression\n     */\n    public function getExpression() -> string\n    {\n        return this->expression;\n    }\n\n    /**\n     * Returns the constraint name (may be an empty string for unnamed)\n     */\n    public function getName() -> string","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Db/Check.zep#L58-L94","documentation":"Even when definition['expression'] exists, Phalcon\\Db\\Check rejects values that are not strings or that are the empty string. A CHECK constraint needs a non-empty SQL boolean expression, so integers, nulls, arrays, or '' all throw InvalidCheckExpression at construction time.","triggerScenarios":"new Check('chk', ['expression' => 0]) or ['expression' => null] after a config miss; expressions built by concatenation that yield ''; JSON payloads where a numeric value stays numeric; using the empty string as a 'no constraint' marker.","commonSituations":"Config-driven constraints where a missing value falls back to '' via ?? ''; API/JSON inputs keeping scalars typed; template concatenation producing empty output; misunderstanding null vs '' semantics (null key absent is a different exception).","solutions":["Normalize the expression to a non-empty string: $expr = trim((string) $expr); and reject '' explicitly.","Validate external input before building the Check: is_string($expr) && $expr !== ''.","Reject constraint config with empty expressions at load time instead of at DDL time."],"exampleFix":"// before\n$expr = $config['check'] ?? '';\n$check = new Check('chk_price', ['expression' => $expr]); // '' throws InvalidCheckExpression\n\n// after\n$expr = trim((string) ($config['check'] ?? ''));\nif ($expr === '') {\n    throw new InvalidArgumentException('Check expression missing in config');\n}\n$check = new Check('chk_price', ['expression' => $expr]);","handlingStrategy":"type-guard","validationCode":"if (!is_string($expr) || $expr === '') {\n    throw new InvalidArgumentException('CHECK expression must be a non-empty string');\n}\n$check = new Check('chk', ['expression' => $expr]);","typeGuard":"function isNonEmptyString(mixed $value): bool\n{\n    return is_string($value) && $value !== '';\n}","tryCatchPattern":null,"preventionTips":["Normalize external config values to strings, rejecting empty ones at the boundary.","Trim and assert non-empty before constructing constraint objects.","Add schema validation for constraint config files."],"tags":["check-constraint","type-validation","phalcon-db"],"backgroundTag":"invalid-parameter-type","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}