diff --git a/UPGRADE.md b/UPGRADE.md index 6d40bf48078..f87814f00ef 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,15 @@ +# Upgrade to 4.0 + +## Remove array access + +Using array access on instances of the following classes is no longer possible: + +- `Doctrine\ORM\Mapping\DiscriminatorColumnMapping` +- `Doctrine\ORM\Mapping\EmbedClassMapping` +- `Doctrine\ORM\Mapping\FieldMapping` +- `Doctrine\ORM\Mapping\JoinColumnMapping` +- `Doctrine\ORM\Mapping\JoinTableMapping` + # Upgrade to 3.1 ## Deprecate passing null to `ClassMetadata::fullyQualifiedClassName()` diff --git a/docs/en/cookbook/aggregate-fields.rst b/docs/en/cookbook/aggregate-fields.rst index 001d70d34b4..20bfa32896f 100644 --- a/docs/en/cookbook/aggregate-fields.rst +++ b/docs/en/cookbook/aggregate-fields.rst @@ -352,7 +352,7 @@ the database using a FOR UPDATE. use Bank\Entities\Account; use Doctrine\DBAL\LockMode; - $account = $em->find(Account::class, $accId, LockMode::PESSIMISTIC_READ); + $account = $em->find(Account::class, $accId, LockMode::PESSIMISTIC_WRITE); Keeping Updates and Deletes in Sync ----------------------------------- diff --git a/src/Mapping/ArrayAccessImplementation.php b/src/Mapping/ArrayAccessImplementation.php deleted file mode 100644 index 3fd0988cf1b..00000000000 --- a/src/Mapping/ArrayAccessImplementation.php +++ /dev/null @@ -1,70 +0,0 @@ -$offset); - } - - /** @param string $offset */ - public function offsetGet(mixed $offset): mixed - { - Deprecation::trigger( - 'doctrine/orm', - 'https://github.com/doctrine/orm/pull/11211', - 'Using ArrayAccess on %s is deprecated and will not be possible in Doctrine ORM 4.0. Use the corresponding property instead.', - static::class, - ); - - if (! property_exists($this, $offset)) { - throw new InvalidArgumentException('Undefined property: ' . $offset); - } - - return $this->$offset; - } - - /** @param string $offset */ - public function offsetSet(mixed $offset, mixed $value): void - { - Deprecation::trigger( - 'doctrine/orm', - 'https://github.com/doctrine/orm/pull/11211', - 'Using ArrayAccess on %s is deprecated and will not be possible in Doctrine ORM 4.0. Use the corresponding property instead.', - static::class, - ); - - $this->$offset = $value; - } - - /** @param string $offset */ - public function offsetUnset(mixed $offset): void - { - Deprecation::trigger( - 'doctrine/orm', - 'https://github.com/doctrine/orm/pull/11211', - 'Using ArrayAccess on %s is deprecated and will not be possible in Doctrine ORM 4.0. Use the corresponding property instead.', - static::class, - ); - - $this->$offset = null; - } -} diff --git a/src/Mapping/AssociationMapping.php b/src/Mapping/AssociationMapping.php index 0253413e8d8..469b3f0ad23 100644 --- a/src/Mapping/AssociationMapping.php +++ b/src/Mapping/AssociationMapping.php @@ -4,7 +4,6 @@ namespace Doctrine\ORM\Mapping; -use ArrayAccess; use Exception; use OutOfRangeException; @@ -14,8 +13,7 @@ use function property_exists; use function sprintf; -/** @template-implements ArrayAccess */ -abstract class AssociationMapping implements ArrayAccess +abstract class AssociationMapping { /** * The names of persistence operations to cascade on the association. diff --git a/src/Mapping/DiscriminatorColumnMapping.php b/src/Mapping/DiscriminatorColumnMapping.php index 4ccb71c4b36..6ac928662bf 100644 --- a/src/Mapping/DiscriminatorColumnMapping.php +++ b/src/Mapping/DiscriminatorColumnMapping.php @@ -4,18 +4,14 @@ namespace Doctrine\ORM\Mapping; -use ArrayAccess; use BackedEnum; use Exception; use function in_array; use function property_exists; -/** @template-implements ArrayAccess */ -final class DiscriminatorColumnMapping implements ArrayAccess +final class DiscriminatorColumnMapping { - use ArrayAccessImplementation; - /** The database length of the column. Optional. Default value taken from the type. */ public int|null $length = null; diff --git a/src/Mapping/EmbeddedClassMapping.php b/src/Mapping/EmbeddedClassMapping.php index c1d464568a8..ae14a0bb2ba 100644 --- a/src/Mapping/EmbeddedClassMapping.php +++ b/src/Mapping/EmbeddedClassMapping.php @@ -4,15 +4,10 @@ namespace Doctrine\ORM\Mapping; -use ArrayAccess; - use function property_exists; -/** @template-implements ArrayAccess */ -final class EmbeddedClassMapping implements ArrayAccess +final class EmbeddedClassMapping { - use ArrayAccessImplementation; - public string|false|null $columnPrefix = null; public string|null $declaredField = null; public string|null $originalField = null; diff --git a/src/Mapping/FieldMapping.php b/src/Mapping/FieldMapping.php index 3e05eba9ec2..2b942b955ec 100644 --- a/src/Mapping/FieldMapping.php +++ b/src/Mapping/FieldMapping.php @@ -4,17 +4,13 @@ namespace Doctrine\ORM\Mapping; -use ArrayAccess; use BackedEnum; use function in_array; use function property_exists; -/** @template-implements ArrayAccess */ -final class FieldMapping implements ArrayAccess +final class FieldMapping { - use ArrayAccessImplementation; - /** The database length of the column. Optional. Default value taken from the type. */ public int|null $length = null; /** diff --git a/src/Mapping/JoinColumnMapping.php b/src/Mapping/JoinColumnMapping.php index bc469bb6494..79574d11bce 100644 --- a/src/Mapping/JoinColumnMapping.php +++ b/src/Mapping/JoinColumnMapping.php @@ -4,15 +4,10 @@ namespace Doctrine\ORM\Mapping; -use ArrayAccess; - use function property_exists; -/** @template-implements ArrayAccess */ -final class JoinColumnMapping implements ArrayAccess +final class JoinColumnMapping { - use ArrayAccessImplementation; - public bool|null $unique = null; public bool|null $quoted = null; public string|null $fieldName = null; diff --git a/src/Mapping/JoinTableMapping.php b/src/Mapping/JoinTableMapping.php index df46f9722a9..2671657fef7 100644 --- a/src/Mapping/JoinTableMapping.php +++ b/src/Mapping/JoinTableMapping.php @@ -4,16 +4,11 @@ namespace Doctrine\ORM\Mapping; -use ArrayAccess; - use function array_map; use function in_array; -/** @template-implements ArrayAccess */ -final class JoinTableMapping implements ArrayAccess +final class JoinTableMapping { - use ArrayAccessImplementation; - public bool|null $quoted = null; /** @var list */ diff --git a/tests/Tests/ORM/Mapping/AssociationMappingTest.php b/tests/Tests/ORM/Mapping/AssociationMappingTest.php index 22c329392bf..d5f29f5b287 100644 --- a/tests/Tests/ORM/Mapping/AssociationMappingTest.php +++ b/tests/Tests/ORM/Mapping/AssociationMappingTest.php @@ -6,7 +6,6 @@ use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata; -use OutOfRangeException; use PHPUnit\Framework\TestCase; use function assert; @@ -50,45 +49,6 @@ public function testItSurvivesSerialization(): void self::assertTrue($resurrectedMapping->orphanRemoval); self::assertTrue($resurrectedMapping->unique); } - - public function testItThrowsWhenAccessingUnknownProperty(): void - { - $mapping = new MyAssociationMapping( - fieldName: 'foo', - sourceEntity: self::class, - targetEntity: self::class, - ); - - $this->expectException(OutOfRangeException::class); - - $mapping['foo']; - } - - public function testItThrowsWhenSettingUnknownProperty(): void - { - $mapping = new MyAssociationMapping( - fieldName: 'foo', - sourceEntity: self::class, - targetEntity: self::class, - ); - - $this->expectException(OutOfRangeException::class); - - $mapping['foo'] = 'bar'; - } - - public function testItThrowsWhenUnsettingUnknownProperty(): void - { - $mapping = new MyAssociationMapping( - fieldName: 'foo', - sourceEntity: self::class, - targetEntity: self::class, - ); - - $this->expectException(OutOfRangeException::class); - - unset($mapping['foo']); - } } class MyAssociationMapping extends AssociationMapping