Skip to content

Commit bbde41f

Browse files
authored
Merge pull request #12005 from greg0ire/depr-no-lazy-objects
Deprecate not using native lazy objects on PHP 8.4+
2 parents 8c0994f + 3d390bc commit bbde41f

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

UPGRADE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Upgrade to 3.5
22

3+
## Deprecate not using native lazy objects on PHP 8.4+
4+
5+
Having native lazy objects disabled on PHP 8.4+ is deprecated and will not be
6+
possible in 4.0.
7+
8+
You can enable them through configuration:
9+
10+
```php
11+
$config->enableNativeLazyObjects(true);
12+
```
13+
314
## Deprecate methods for configuring no longer configurable features
415

516
Since 3.0, lazy ghosts are enabled unconditionally, and so is rejecting ID

src/Configuration.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\ORM;
66

77
use Doctrine\DBAL\Platforms\AbstractPlatform;
8+
use Doctrine\Deprecations\Deprecation;
89
use Doctrine\ORM\Cache\CacheConfiguration;
910
use Doctrine\ORM\Exception\InvalidEntityRepository;
1011
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
@@ -597,11 +598,29 @@ public function setSchemaIgnoreClasses(array $schemaIgnoreClasses): void
597598

598599
public function isNativeLazyObjectsEnabled(): bool
599600
{
600-
return $this->attributes['nativeLazyObjects'] ?? false;
601+
$nativeLazyObjects = $this->attributes['nativeLazyObjects'] ?? false;
602+
603+
if (! $nativeLazyObjects && PHP_VERSION_ID >= 80400) {
604+
Deprecation::trigger(
605+
'doctrine/orm',
606+
'https://github.com/doctrine/orm/pull/12005',
607+
'Not enabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0.',
608+
);
609+
}
610+
611+
return $nativeLazyObjects;
601612
}
602613

603614
public function enableNativeLazyObjects(bool $nativeLazyObjects): void
604615
{
616+
if (! $nativeLazyObjects) {
617+
Deprecation::trigger(
618+
'doctrine/orm',
619+
'https://github.com/doctrine/orm/pull/12005',
620+
'Disabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0.',
621+
);
622+
}
623+
605624
if (PHP_VERSION_ID < 80400) {
606625
throw new LogicException('Lazy loading proxies require PHP 8.4 or higher.');
607626
}

tests/Tests/ORM/ConfigurationTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\Tests\ORM;
66

7+
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
78
use Doctrine\ORM\Cache\CacheConfiguration;
89
use Doctrine\ORM\Configuration;
910
use Doctrine\ORM\EntityRepository;
@@ -17,6 +18,8 @@
1718
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
1819
use Doctrine\Tests\Models\DDC753\DDC753CustomRepository;
1920
use PHPUnit\Framework\Attributes\Group;
21+
use PHPUnit\Framework\Attributes\RequiresPhp;
22+
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
2023
use PHPUnit\Framework\TestCase;
2124
use Psr\Cache\CacheItemPoolInterface;
2225

@@ -25,6 +28,8 @@
2528
*/
2629
class ConfigurationTest extends TestCase
2730
{
31+
use VerifyDeprecations;
32+
2833
private Configuration $configuration;
2934

3035
protected function setUp(): void
@@ -212,4 +217,28 @@ public function testSetGetTypedFieldMapper(): void
212217
$this->configuration->setTypedFieldMapper($defaultTypedFieldMapper);
213218
self::assertSame($defaultTypedFieldMapper, $this->configuration->getTypedFieldMapper());
214219
}
220+
221+
#[RequiresPhp('8.4')]
222+
#[WithoutErrorHandler]
223+
public function testDisablingNativeLazyObjectsIsDeprecated(): void
224+
{
225+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
226+
227+
$this->configuration->enableNativeLazyObjects(false);
228+
}
229+
230+
#[RequiresPhp('<8.4')]
231+
public function testNotEnablingNativeLazyObjectIsFineOnPhpLowerThan84(): void
232+
{
233+
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
234+
self::assertFalse($this->configuration->isNativeLazyObjectsEnabled());
235+
}
236+
237+
#[RequiresPhp('8.4')]
238+
#[WithoutErrorHandler]
239+
public function testNotEnablingNativeLazyObjectIsDeprecatedOnPhp84(): void
240+
{
241+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
242+
self::assertFalse($this->configuration->isNativeLazyObjectsEnabled());
243+
}
215244
}

0 commit comments

Comments
 (0)