Skip to content

Checking maxProperties when payload is not an object generates PHP Warning #260

@mirfilip

Description

@mirfilip
  • package version used: 2.0.1 (9ef71fd)
  • schema
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "foo": {
      "type": "object",
      "maxProperties": 1,
      "additionalProperties": false,
      "patternProperties": {
        "^[a-zA-Z]+$": {
          "type": "boolean"
        }
      }
    }
  }
}
  • input:
{
  "foo": 123
}

It generates:

PHP Warning:  get_object_vars() expects parameter 1 to be object, integer given in /tmp/repro/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/ObjectConstraint.php on line 169

I think it shouldn't attempt to do anything with ObjectConstraint when the payload is not an object.

For comparison, version 1.6.1 (cc84765) produces no warning (and validates properly).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions