PHP7.2+ compatible strict types and type hinting

This commit is contained in:
Pen-y-Fan
2020-05-18 22:50:05 +01:00
parent 8500dd433d
commit 9cf94c2653
3 changed files with 46 additions and 15 deletions

View File

@@ -1,16 +1,24 @@
<?php
declare(strict_types=1);
namespace Theatrical;
class Invoice
{
public string $customer;
public array $performances;
/**
* @var string
*/
public $customer;
public function __construct($customer, $performances)
/**
* @var array
*/
public $performances;
public function __construct(string $customer, array $performances)
{
$this->customer = $customer;
$this->performances = $performances;
}
}
}

View File

@@ -1,15 +1,29 @@
<?php
declare(strict_types=1);
namespace Theatrical;
class Performance
class Performance
{
public string $play_id;
public int $audience;
/**
* @var string
*/
public $play_id;
public function __construct($play_id, $audience)
/**
* @var int
*/
public $audience;
/**
* @var Play
*/
public $play;
public function __construct(string $play_id, int $audience)
{
$this->play_id = $play_id;
$this->audience = $audience;
}
}
}

View File

@@ -1,13 +1,22 @@
<?php
declare(strict_types=1);
namespace Theatrical;
class Play
class Play
{
public string $name;
public string $type;
/**
* @var string
*/
public $name;
public function __construct($name, $type)
/**
* @var string
*/
public $type;
public function __construct(string $name, string $type)
{
$this->name = $name;
$this->type = $type;
@@ -17,4 +26,4 @@ class Play
{
return (string) $this->name . ' : ' . $this->type;
}
}
}