merged branch willdurand/undefined-value-property-path (PR #2266)

Commits
-------

57e1aeb Fixed undefined index notice in readProperty() method (PropertyPath)

Discussion
----------

Fixed undefined index notice in readProperty() method (PropertyPath)

Hi,

For some reasons, I get `notice` errors on `readProperty()` with Propel:

    Notice: Undefined index: 0 in /Users/william/projects/Propel/testProjects/symfony2/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php line 284

The `PropelObjectCollection` implements `ArrayAccess`, the `readProperty()` method does not check if the given `index` exists so the `notice` error is thrown. I suppose to check whether the index exists or not has to be added.

Regards,
William

---------------------------------------------------------------------------

by fabpot at 2011/09/27 23:42:07 -0700

The patch is probably not what we want to do. First, I suppose that you are not creating the propertyPath by hand. If that is the case, we need to understand why the property path does not exist. Then, even if we might want to check the existence of the index, if it does not exist, we should probably throw an exception instead of just ignoring the problem.

---------------------------------------------------------------------------

by willdurand at 2011/09/28 01:14:49 -0700

My bad. This is a Propel bug due to `ArrayObject`. It throws a notice error if the index is not found in `offsetGet()` which is wrong according to the `ArrayAccess` interface. If the index is not found, we have to return `null`.

@fabpot Are you agree with that (for the `null` value) ?

---------------------------------------------------------------------------

by fabpot at 2011/09/28 01:17:09 -0700

My point is that it should never happen under normal circumstances.

---------------------------------------------------------------------------

by willdurand at 2011/09/28 01:23:55 -0700

@fabpot Not sure to get it.

The fact is that it tries to get the value (`getValue()`) of a fresh object, just added to the `collection` when I'm submitting a form with a `CollectionType` and a new entry in it.
I mean it tries to get this new object (not yet persisted, not yet in the collection) in the collection (`getValue()` -> `readProperty()`) which implements `ArrayAccess` but this object cannot be in the collection at this time.

Am I wrong ?

And, without this notice error thrown by Propel, I probably never opened this issue...

---------------------------------------------------------------------------

by willdurand at 2011/09/29 06:40:34 -0700

@fabpot: you can try this example: http://www.propelorm.org/cookbook/symfony2/mastering-symfony2-forms-with-propel.html#manytomany_relations in order to make your own tests. Will it be enough?
As I said, it throws a weird notice for the reasons above.

---------------------------------------------------------------------------

by jaugustin at 2011/10/04 12:58:10 -0700

any news on this ?
@fabpot did you have time to look at the test case ?

---------------------------------------------------------------------------

by cedriclombardot at 2011/11/09 14:29:42 -0800

@fabpot: can we have news about this ?
This commit is contained in:
Fabien Potencier 2011-11-22 09:55:47 +01:00
commit 7c8d836331

View File

@ -279,7 +279,9 @@ class PropertyPath implements \IteratorAggregate
throw new InvalidPropertyException(sprintf('Index "%s" cannot be read from object of type "%s" because it doesn\'t implement \ArrayAccess', $property, get_class($object)));
}
return $object[$property];
if (isset($object[$property])) {
return $object[$property];
}
} else {
$camelProp = $this->camelize($property);
$reflClass = new \ReflectionClass($object);