Skip to content

[Bug]: getObjectGraph warning for multiple instances is unreachable #293

Backlog

Description

@Ibochkarev

Summary

xPDO::getObjectGraph() contains a condition that can never be true, so its "criteria returned more than one instance" warning is unreachable. When criteria match several rows, the method silently returns the first object.

Steps to Reproduce

  1. Build a query whose criteria match more than one object.
  2. Call $xpdo->getObjectGraph($class, $graph, $criteria).
  3. Watch the log and the returned object.

Expected Behavior

A warning when criteria match more than one instance.

Actual / Observed Behavior

src/xPDO/xPDO.php:1088 uses if (!count($collection) === 1), which is always false because !count(...) is a boolean compared to the integer 1. reset($collection) on line 1091 then returns the first object with no warning.

Environment

xPDO Version: 3.2.0, commit e0d7dfd6c58e38767094aff1bc049d7694a05735
PHP Version: not provided (report based on source review)
Database: not applicable

Logs / Error Output

No warning is written.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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