"value":"\n <p>Continuing with yesterday's data transfer object (DTO) example, something that can be done since PHP 8.1 is to make properties read-only:<\/p>\n\n<pre><code class=\"language-php\">class AccountDetails {\n\n public function __construct(\n public readonly string $accountNumber,\n public readonly string $sortCode,\n ) {}\n\n}\n<\/code><\/pre>\n\n<p>This means the public properties can be read and used without the need for getter methods, but cannot be overridden - making the DTO immutable.<\/p>\n\n<p>Without <code>readonly<\/code>, a DTO can be created and the property values can be changed:<\/p>\n\n<pre><code class=\"language-php\">$accountDetails = new AccountDetails('12345678', '00-00-00');\n$accountDetails->accountNumber = 'banana';\n<\/code><\/pre>\n\n<p>With <code>readonly<\/code> set, you'd get a fatal error instead:<\/p>\n\n<blockquote>\n <p>Fatal error: Uncaught Error: Cannot modify readonly property AccountDetails::$accountNumber in \/home\/opdavies\/tmp\/example.php:13<\/p>\n<\/blockquote>\n\n ",
"format":"full_html",
"processed":"\n <p>Continuing with yesterday's data transfer object (DTO) example, something that can be done since PHP 8.1 is to make properties read-only:<\/p>\n\n<pre><code class=\"language-php\">class AccountDetails {\n\n public function __construct(\n public readonly string $accountNumber,\n public readonly string $sortCode,\n ) {}\n\n}\n<\/code><\/pre>\n\n<p>This means the public properties can be read and used without the need for getter methods, but cannot be overridden - making the DTO immutable.<\/p>\n\n<p>Without <code>readonly<\/code>, a DTO can be created and the property values can be changed:<\/p>\n\n<pre><code class=\"language-php\">$accountDetails = new AccountDetails('12345678', '00-00-00');\n$accountDetails->accountNumber = 'banana';\n<\/code><\/pre>\n\n<p>With <code>readonly<\/code> set, you'd get a fatal error instead:<\/p>\n\n<blockquote>\n <p>Fatal error: Uncaught Error: Cannot modify readonly property AccountDetails::$accountNumber in \/home\/opdavies\/tmp\/example.php:13<\/p>\n<\/blockquote>\n\n ",