webmozarts / assert

Assertions to validate method input/output with nice error messages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Method "allPropertyExists" and similar throw fatal error

adevyatov opened this issue · comments

$std = new \stdClass();
$std->some = null;
$std->some2 = null;

// it's ok
Webmozart\Assert\Assert::propertyExists($std, 'some');

// but "all" method throws fatal exception
Webmozart\Assert\Assert::allPropertyExists(['some', 'some2'], $std);

PHP Fatal error: Uncaught InvalidArgumentException: Expected the property stdClass to exist.

Because first argument is class/object, not property.
public static function propertyExists($classOrObject, $property, $message = '')

Problem occurs in the methods:

  • allPropertyExists
  • allPropertyNotExists
  • allMethodExists
  • allMethodNotExists

As I understand it, currently the allPropertyExists method does not check multiple properties on one object/class.
It checks one property against an array of objects/classes.

Example:

$dog = new \stdClass();
$dog->name = 'odie';
$cat = new \stdClass();
$cat->name = 'garfield';

// This would run fine.
Webmozart\Assert\Assert::allPropertyExists([$dog, $cat], 'name');

@FrontEndCoffee I see... So, this isn't a bug, right?