@@ -244,9 +244,9 @@ Assume you have the following plain-old-PHP object::
244
244
245
245
class MyObj
246
246
{
247
- public $foo;
247
+ public string $foo;
248
248
249
- private $bar;
249
+ private string $bar;
250
250
251
251
public function getBar()
252
252
{
@@ -303,10 +303,10 @@ Then, create your groups definition:
303
303
class MyObj
304
304
{
305
305
#[Groups(['group1', 'group2'])]
306
- public $foo;
306
+ public string $foo;
307
307
308
308
#[Groups(['group4'])]
309
- public $anotherProperty;
309
+ public string $anotherProperty;
310
310
311
311
#[Groups(['group3'])]
312
312
public function getBar() // is* methods are also supported
@@ -449,10 +449,10 @@ Option 1: Using ``@Ignore`` Annotation
449
449
450
450
class MyClass
451
451
{
452
- public $foo;
452
+ public string $foo;
453
453
454
454
#[Ignore]
455
- public $bar;
455
+ public string $bar;
456
456
}
457
457
458
458
.. code-block :: yaml
@@ -1229,8 +1229,8 @@ You can change this behavior by setting the ``AbstractObjectNormalizer::SKIP_NUL
1229
1229
to ``true ``::
1230
1230
1231
1231
$dummy = new class {
1232
- public $foo;
1233
- public $bar = 'notNull';
1232
+ public ?string $foo = null ;
1233
+ public string $bar = 'notNull';
1234
1234
};
1235
1235
1236
1236
$normalizer = new ObjectNormalizer();
@@ -1305,8 +1305,8 @@ Circular references are common when dealing with entity relations::
1305
1305
1306
1306
class Organization
1307
1307
{
1308
- private $name;
1309
- private $members;
1308
+ private string $name;
1309
+ private array $members;
1310
1310
1311
1311
public function setName($name)
1312
1312
{
@@ -1331,10 +1331,10 @@ Circular references are common when dealing with entity relations::
1331
1331
1332
1332
class Member
1333
1333
{
1334
- private $name;
1335
- private $organization;
1334
+ private string $name;
1335
+ private Organization $organization;
1336
1336
1337
- public function setName($name)
1337
+ public function setName(string $name)
1338
1338
{
1339
1339
$this->name = $name;
1340
1340
}
@@ -1404,12 +1404,12 @@ structure::
1404
1404
1405
1405
class MyObj
1406
1406
{
1407
- public $foo;
1407
+ public string $foo;
1408
1408
1409
1409
/**
1410
1410
* @var self
1411
1411
*/
1412
- public $child;
1412
+ public MyObj $child;
1413
1413
}
1414
1414
1415
1415
$level1 = new MyObj();
@@ -1437,7 +1437,7 @@ Here, we set it to 2 for the ``$child`` property:
1437
1437
class MyObj
1438
1438
{
1439
1439
#[MaxDepth(2)]
1440
- public $child;
1440
+ public MyObj $child;
1441
1441
1442
1442
// ...
1443
1443
}
@@ -1499,10 +1499,10 @@ having unique identifiers::
1499
1499
1500
1500
class Foo
1501
1501
{
1502
- public $id;
1502
+ public int $id;
1503
1503
1504
1504
#[MaxDepth(1)]
1505
- public $child;
1505
+ public MyObj $child;
1506
1506
}
1507
1507
1508
1508
$level1 = new Foo();
@@ -1598,8 +1598,8 @@ context option::
1598
1598
class MyObj
1599
1599
{
1600
1600
public function __construct(
1601
- private $foo,
1602
- private $bar,
1601
+ private string $foo,
1602
+ private string $bar,
1603
1603
) {
1604
1604
}
1605
1605
}
@@ -1638,8 +1638,8 @@ parameter of the ``ObjectNormalizer``::
1638
1638
1639
1639
class ObjectOuter
1640
1640
{
1641
- private $inner;
1642
- private $date;
1641
+ private ObjectInner $inner;
1642
+ private \DateTimeInterface $date;
1643
1643
1644
1644
public function getInner()
1645
1645
{
@@ -1664,8 +1664,8 @@ parameter of the ``ObjectNormalizer``::
1664
1664
1665
1665
class ObjectInner
1666
1666
{
1667
- public $foo;
1668
- public $bar;
1667
+ public string $foo;
1668
+ public string $bar;
1669
1669
}
1670
1670
1671
1671
$normalizer = new ObjectNormalizer(null, null, null, new ReflectionExtractor());
0 commit comments