{"record":{"id":"f01bea9fe35d7baf","repo":"bcit-ci/CodeIgniter","slug":"form-validation-set-rules-expect-rules-to-be-s","errorCode":null,"errorMessage":"Form_validation: set_rules() expect $rules to be string or array; $type given","messagePattern":"Form_validation: set_rules\\(\\) expect \\$rules to be string or array; \\$type given","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"system/libraries/Form_validation.php","lineNumber":209,"sourceCode":"\n\t\t\treturn $this;\n\t\t}\n\t\telseif ( ! isset($rules))\n\t\t{\n\t\t\tthrow new BadMethodCallException('Form_validation: set_rules() called without a $rules parameter');\n\t\t}\n\n\t\t// No fields or no rules? Nothing to do...\n\t\tif ( ! is_string($field) OR $field === '' OR empty($rules))\n\t\t{\n\t\t\tthrow new RuntimeException('Form_validation: set_rules() called with an empty $rules parameter');\n\t\t}\n\t\telseif ( ! is_array($rules))\n\t\t{\n\t\t\t// BC: Convert pipe-separated rules string to an array\n\t\t\tif ( ! is_string($rules))\n\t\t\t{\n\t\t\t\tthrow new InvalidArgumentException('Form_validation: set_rules() expect $rules to be string or array; '.gettype($rules).' given');\n\t\t\t}\n\n\t\t\t$rules = preg_split('/\\|(?![^\\[]*\\])/', $rules);\n\t\t}\n\n\t\t// If the field label wasn't passed we use the field name\n\t\t$label = ($label === '') ? $field : $label;\n\n\t\t$indexes = array();\n\n\t\t// Is the field name an array? If it is an array, we break it apart\n\t\t// into its components so that we can fetch the corresponding POST data later\n\t\tif (($is_array = (bool) preg_match_all('/\\[(.*?)\\]/', $field, $matches)) === TRUE)\n\t\t{\n\t\t\tsscanf($field, '%[^[][', $indexes[0]);\n\n\t\t\tfor ($i = 0, $c = count($matches[0]); $i < $c; $i++)\n\t\t\t{","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/bcit-ci/CodeIgniter/blob/3658d731eaabe6117298a105ffb5b9dd59e190ce/system/libraries/Form_validation.php#L191-L227","documentation":"Error \"Form_validation: set_rules() expect $rules to be string or array; $type given\" thrown in bcit-ci/CodeIgniter.","triggerScenarios":"Thrown at system/libraries/Form_validation.php:209 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3658d731eaabe6117298a105ffb5b9dd59e190ce","analyzedAt":"2026-08-17T02:34:56.929Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}