{"id":2381,"date":"2018-10-28T10:07:07","date_gmt":"2018-10-28T09:07:07","guid":{"rendered":"https:\/\/www.entropywins.wtf\/blog\/?p=2381"},"modified":"2019-08-20T03:35:41","modified_gmt":"2019-08-20T02:35:41","slug":"php-typed-properties","status":"publish","type":"post","link":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/","title":{"rendered":"PHP Typed Properties"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2389\" data-permalink=\"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/php-3\/\" data-orig-file=\"https:\/\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png\" data-orig-size=\"2000,1371\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"php\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png\" class=\"wp-image-2389 alignright\" src=\"https:\/\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png\" alt=\"\" width=\"169\" height=\"116\" \/>Lately there has been a lot of hype around the typed properties that PHP 7.4 will bring. In this post I outline why typed properties are not as big of a game changer as some people seem to think and how they can lead to shitty code. I start by a short introduction to what typed properties are.<\/p>\n<h3>What Are Typed Properties<\/h3>\n<p>As of version 7.3, PHP supports <a href=\"https:\/\/secure.php.net\/manual\/en\/functions.arguments.php#functions.arguments.type-declaration\">types for function parameters<\/a> and for function return values. Over the latest years many additions to PHP types where made, such as <a href=\"https:\/\/secure.php.net\/manual\/en\/language.types.intro.php\">primitive (scalar) types<\/a> like <code>string<\/code> and <code>int<\/code> (PHP 7.0), <a href=\"https:\/\/secure.php.net\/manual\/en\/functions.returning-values.php\">return types<\/a> (PHP 7.0), <a href=\"https:\/\/www.entropywins.wtf\/blog\/2016\/12\/02\/php-7-1-is-awesome\/\">nullable types<\/a> (PHP 7.1) and <a href=\"https:\/\/secure.php.net\/manual\/en\/migration72.new-features.php\">parameter type widening<\/a> (PHP 7.2). The introduction of <a href=\"https:\/\/wiki.php.net\/rfc\/typed_properties_v2\">typed properties<\/a> (PHP 7.4) is thus a natural progression.<\/p>\n<p>Typed properties work as follows:<\/p>\n<pre class=\"lang:php decode:true\">class User {\n    public int $id;\n    public string $name;\n \n    public function __construct(int $id, string $name) {\n        $this-&gt;id = $id;\n        $this-&gt;name = $name;\n    }\n}<\/pre>\n<p>You can do in two simple lines what takes a lot more boilerplate in PHP 7.3 or earlier. In these versions, if you want to have type safety, you need a getter and setter for each property.<\/p>\n<pre class=\"lang:php decode:true\">\u00a0   private $id;\n    private $name;\n\n    public function getId(): int {\n        return $this-&gt;id;\n    }\n    public function setId(int $id): void {\n        $this-&gt;id = $id;\n    }\n \n    public function getName(): string {\n        return $this-&gt;name;\n    }\n    public function setName(string $name): void {\n        $this-&gt;id = $name;\n    }<\/pre>\n<p>Not only is it a lot more work to write all of these getters and setters, it is also easy to make mistakes when not automatically generating the code with some tool.<\/p>\n<p>These advantages are what the hype is all about. People are saying it will save us from writing so much code. I think not, and I am afraid of the type of code those people will write using typed properties.<\/p>\n<h3>Applicability of Typed Properties<\/h3>\n<p>Let&#8217;s look at some of different types of classes we have in a typical well designed OO codebase.<\/p>\n<p>Services are classes that allow doing something. Loggers are services, Repositories are services and LolcatPrinters are services. Services often need collaborators, which get injected via their constructor and stored in private fields. These collaborators are not visible from the outside. While services might have additional state, they normally do not have getters or setters. Typed properties thus do not save us from writing code when creating services and the added type safety they provide is negligible.<\/p>\n<p>Entities (DDD term) encapsulate both data and behavior. Normally their constructors take a bunch of values, typically in the form of Value Objects. The methods on entities provide ways to manipulate these values via actions that make sense in the domain language. There might be some getters, though setters are rare. Having getters and setters for most of the values in your entities is an anti-pattern. Again typed properties do not save us from writing code in most cases.<\/p>\n<p>Value Objects (DDD term) are <a href=\"https:\/\/en.wikipedia.org\/wiki\/Immutable_object\">immutable<\/a>. This means you can have getters but not setters. Once again typed properties are of no real help. What would be really helpful however is a <a href=\"https:\/\/www.entropywins.wtf\/blog\/2016\/02\/03\/missing-in-php7-value-objects\/\">first-class Value Object construct part of the PHP language<\/a>.<\/p>\n<p>Typed properties are only useful when you have public mutable state with no <a href=\"https:\/\/en.wikipedia.org\/wiki\/Encapsulation_(computer_programming)\">encapsulation<\/a>. (And in some cases where you assign to private fields after doing complicated things.) If you design your code well, you will have very little code that matches all of these criteria.<\/p>\n<h3>Going to The Dark Side<\/h3>\n<p>By throwing immutability and encapsulation out of the window, you can often condense code using typed properties. This standard Value Object &#8230;<\/p>\n<pre class=\"lang:php decode:true \">class Name {\n    private $firstName;\n    private $lastName;\n \n    public function __construct(string $firstName, string $lastName) {\n        $this-&gt;firstName = $firstName;\n        $this-&gt;lastName = $lastName;\n    }\n \n    public function getFirstName(): string {\n        return $this-&gt;firstName;\n    }\n\n    public function getLastName(): string {\n        return $this-&gt;lastName;\n    }\n}<\/pre>\n<p>&#8230; becomes the much shorter<\/p>\n<pre class=\"lang:php decode:true  \">class Name {\n    public string $firstName;\n    public string $lastName;\n \n    public function __construct(string $firstName, string $lastName) {\n        $this-&gt;firstName = $firstName;\n        $this-&gt;lastName = $lastName;\n    }\n}<\/pre>\n<p>The same goes for Services and Entities: by giving up on encapsulation and immutability, you gain the ability to not write a few lines of simple code.<\/p>\n<p>This trade-off might actually make sense if you are working on a small codebase on your own or with few people. It can also make sense if you create a throw away prototype that you then actually throw away. For codebases that are not small and are worked on by several people writing a few simple getters is a low price to pay for the advantages that encapsulation and immutability provide.<\/p>\n<h3>Conclusion<\/h3>\n<p>Typed properties marginally help with type safety and in some rare cases can help reduce boilerplate code. In most cases typed properties do not reduce the amount of code needed unless you throw the valuable properties of immutability and encapsulation out of the window. Due to the hype I expect many junior programmers to do exactly that.<\/p>\n<h3>See Also<\/h3>\n<ul>\n<li><a href=\"https:\/\/www.entropywins.wtf\/blog\/2016\/02\/03\/missing-in-php7-value-objects\/\">Missing in PHP7: Value Objects<\/a><\/li>\n<li><a href=\"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/16\/introduction-to-iterators-and-generators-in-php\/\">Introduction to Iterators and Generators in PHP<\/a><\/li>\n<li><a href=\"https:\/\/www.entropywins.wtf\/blog\/2017\/09\/06\/the-fallacy-of-dry\/\">The Fallacy of DRY<\/a><\/li>\n<li><a href=\"https:\/\/www.entropywins.wtf\/blog\/2018\/01\/20\/php-project-template\/\">PHP project template<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Lately there has been a lot of hype around the typed properties that PHP 7.4 will bring. In this post&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[452,328,415,459,195,441,197,269,409,404],"class_list":["post-2381","post","type-post","status-publish","format-standard","hentry","category-programming","tag-anti-patterns","tag-clean-code","tag-encapsulation","tag-immutability","tag-php","tag-php7","tag-planet-wikimedia","tag-type","tag-type-hinting","tag-value-objects"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHP Typed Properties - Blog of Jeroen De Dauw<\/title>\n<meta name=\"description\" content=\"The impact of PHP typed properties. Do they live up to the hype?\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Typed Properties - Blog of Jeroen De Dauw\" \/>\n<meta property=\"og:description\" content=\"The impact of PHP typed properties. Do they live up to the hype?\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog of Jeroen De Dauw\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-28T09:07:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-08-20T02:35:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png\" \/>\n<meta name=\"author\" content=\"Jeroen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:description\" content=\"Why Typed Properties are not the next big thing in PHP\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/JeroenDeDauw\" \/>\n<meta name=\"twitter:site\" content=\"@JeroenDeDauw\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeroen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/\"},\"author\":{\"name\":\"Jeroen\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/#\\\/schema\\\/person\\\/4e2ef14f2ca7dc3a0ac137d1692b66b7\"},\"headline\":\"PHP Typed Properties\",\"datePublished\":\"2018-10-28T09:07:07+00:00\",\"dateModified\":\"2019-08-20T02:35:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/\"},\"wordCount\":704,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/#\\\/schema\\\/person\\\/4e2ef14f2ca7dc3a0ac137d1692b66b7\"},\"image\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/10\\\/php-1.png\",\"keywords\":[\"Anti-patterns\",\"Clean Code\",\"Encapsulation\",\"Immutability\",\"PHP\",\"PHP7\",\"Planet Wikimedia\",\"Type\",\"Type hinting\",\"Value objects\"],\"articleSection\":[\"Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/\",\"url\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/\",\"name\":\"PHP Typed Properties - Blog of Jeroen De Dauw\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/10\\\/php-1.png\",\"datePublished\":\"2018-10-28T09:07:07+00:00\",\"dateModified\":\"2019-08-20T02:35:41+00:00\",\"description\":\"The impact of PHP typed properties. Do they live up to the hype?\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/10\\\/php-1.png\",\"contentUrl\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/10\\\/php-1.png\",\"width\":2000,\"height\":1371},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2018\\\/10\\\/28\\\/php-typed-properties\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP Typed Properties\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/\",\"name\":\"Entropy Wins\",\"description\":\"A blog on Software Architecture, Design and Craftsmanship\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/#\\\/schema\\\/person\\\/4e2ef14f2ca7dc3a0ac137d1692b66b7\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/#\\\/schema\\\/person\\\/4e2ef14f2ca7dc3a0ac137d1692b66b7\",\"name\":\"Jeroen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d62e6b5b8e332335cf17854fac850d9c70ba367c4692872613c3110ebd4e009b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d62e6b5b8e332335cf17854fac850d9c70ba367c4692872613c3110ebd4e009b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d62e6b5b8e332335cf17854fac850d9c70ba367c4692872613c3110ebd4e009b?s=96&d=mm&r=g\",\"caption\":\"Jeroen\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d62e6b5b8e332335cf17854fac850d9c70ba367c4692872613c3110ebd4e009b?s=96&d=mm&r=g\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/jeroendedauw\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/JeroenDeDauw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Typed Properties - Blog of Jeroen De Dauw","description":"The impact of PHP typed properties. Do they live up to the hype?","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/","og_locale":"en_US","og_type":"article","og_title":"PHP Typed Properties - Blog of Jeroen De Dauw","og_description":"The impact of PHP typed properties. Do they live up to the hype?","og_url":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/","og_site_name":"Blog of Jeroen De Dauw","article_published_time":"2018-10-28T09:07:07+00:00","article_modified_time":"2019-08-20T02:35:41+00:00","og_image":[{"url":"https:\/\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png","type":"","width":"","height":""}],"author":"Jeroen","twitter_card":"summary_large_image","twitter_description":"Why Typed Properties are not the next big thing in PHP","twitter_image":"https:\/\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png","twitter_creator":"@https:\/\/twitter.com\/JeroenDeDauw","twitter_site":"@JeroenDeDauw","twitter_misc":{"Written by":"Jeroen","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/#article","isPartOf":{"@id":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/"},"author":{"name":"Jeroen","@id":"https:\/\/www.entropywins.wtf\/blog\/#\/schema\/person\/4e2ef14f2ca7dc3a0ac137d1692b66b7"},"headline":"PHP Typed Properties","datePublished":"2018-10-28T09:07:07+00:00","dateModified":"2019-08-20T02:35:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/"},"wordCount":704,"commentCount":3,"publisher":{"@id":"https:\/\/www.entropywins.wtf\/blog\/#\/schema\/person\/4e2ef14f2ca7dc3a0ac137d1692b66b7"},"image":{"@id":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/#primaryimage"},"thumbnailUrl":"https:\/\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png","keywords":["Anti-patterns","Clean Code","Encapsulation","Immutability","PHP","PHP7","Planet Wikimedia","Type","Type hinting","Value objects"],"articleSection":["Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/","url":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/","name":"PHP Typed Properties - Blog of Jeroen De Dauw","isPartOf":{"@id":"https:\/\/www.entropywins.wtf\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/#primaryimage"},"image":{"@id":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/#primaryimage"},"thumbnailUrl":"https:\/\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png","datePublished":"2018-10-28T09:07:07+00:00","dateModified":"2019-08-20T02:35:41+00:00","description":"The impact of PHP typed properties. Do they live up to the hype?","breadcrumb":{"@id":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/#primaryimage","url":"https:\/\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png","contentUrl":"https:\/\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png","width":2000,"height":1371},{"@type":"BreadcrumbList","@id":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.entropywins.wtf\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP Typed Properties"}]},{"@type":"WebSite","@id":"https:\/\/www.entropywins.wtf\/blog\/#website","url":"https:\/\/www.entropywins.wtf\/blog\/","name":"Entropy Wins","description":"A blog on Software Architecture, Design and Craftsmanship","publisher":{"@id":"https:\/\/www.entropywins.wtf\/blog\/#\/schema\/person\/4e2ef14f2ca7dc3a0ac137d1692b66b7"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.entropywins.wtf\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.entropywins.wtf\/blog\/#\/schema\/person\/4e2ef14f2ca7dc3a0ac137d1692b66b7","name":"Jeroen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d62e6b5b8e332335cf17854fac850d9c70ba367c4692872613c3110ebd4e009b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d62e6b5b8e332335cf17854fac850d9c70ba367c4692872613c3110ebd4e009b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d62e6b5b8e332335cf17854fac850d9c70ba367c4692872613c3110ebd4e009b?s=96&d=mm&r=g","caption":"Jeroen"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/d62e6b5b8e332335cf17854fac850d9c70ba367c4692872613c3110ebd4e009b?s=96&d=mm&r=g"},"sameAs":["https:\/\/www.linkedin.com\/in\/jeroendedauw\/","https:\/\/x.com\/https:\/\/twitter.com\/JeroenDeDauw"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p74TBF-Cp","jetpack-related-posts":[{"id":2848,"url":"https:\/\/www.entropywins.wtf\/blog\/2022\/01\/30\/value-objects-with-php-8-1\/","url_meta":{"origin":2381,"position":0},"title":"Value Objects with PHP 8.1","author":"Jeroen","date":"2022-01-30","format":false,"excerpt":"PHP has introduced a number of new features that allow you to write awesome Value Objects with PHP 8.1. In this post you will learn about each feature and how to put them all together. Back in the dark ages of 2016, shortly after PHP 7.0 was released, I wrote\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.entropywins.wtf\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2016\/02\/i-will-always-favor-value-objects.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2016\/02\/i-will-always-favor-value-objects.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2016\/02\/i-will-always-favor-value-objects.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1577,"url":"https:\/\/www.entropywins.wtf\/blog\/2016\/01\/30\/missing-in-php7-function-references\/","url_meta":{"origin":2381,"position":1},"title":"Missing in PHP7: function references","author":"Jeroen","date":"2016-01-30","format":false,"excerpt":"This is the first post in my Missing in PHP7 series. Over time, PHP has improved its capabilities with regards to functions.\u00a0As of PHP 5.3 you can create anonymous functions and as of 5.4 you can use the callable type hint. However referencing a function still requires using a string.\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.entropywins.wtf\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1548,"url":"https:\/\/www.entropywins.wtf\/blog\/2016\/01\/30\/missing-in-php7\/","url_meta":{"origin":2381,"position":2},"title":"Missing in PHP7","author":"Jeroen","date":"2016-01-30","format":false,"excerpt":"I've decided to start a series of short blog posts on how PHP gets in the way of\u00a0creating of well designed applications, with a focus on missing features. The language flamewar PHP is one of those languages that people love to hate. Its standard library is widely inconsistent, and its\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.entropywins.wtf\/blog\/category\/programming\/"},"img":{"alt_text":"PHP7","src":"https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2016\/01\/PHP7.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":248,"url":"https:\/\/www.entropywins.wtf\/blog\/2009\/07\/26\/on-to-0-2-refactoring-fun\/","url_meta":{"origin":2381,"position":3},"title":"On to 0.2 &#8211; Refactoring fun","author":"Jeroen","date":"2009-07-26","format":false,"excerpt":"Since the 0.1 release of Maps and Semantic Maps, I've gotten quite some feedback on what features are in demand and what could be improved. Although I've not gotten any specific feedback on the extensions source code itself, I decided that refactoring it to get it as high quality as\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.entropywins.wtf\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1629,"url":"https:\/\/www.entropywins.wtf\/blog\/2016\/02\/22\/missing-in-php7-collections\/","url_meta":{"origin":2381,"position":4},"title":"Missing in PHP7: Collections","author":"Jeroen","date":"2016-02-22","format":false,"excerpt":"This is the fourth post in my Missing in PHP7 series. The previous one is about Value Objects. In this post I'll outline some problems PHP has with regards to collections, the implications of those problems, and a few mitigation strategies. PHP arrays PHPs main collection type is the associative\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.entropywins.wtf\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2016\/02\/dfp.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2016\/02\/dfp.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2016\/02\/dfp.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2016\/02\/dfp.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1642,"url":"https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/","url_meta":{"origin":2381,"position":5},"title":"Missing in PHP7: Nullable return types","author":"Jeroen","date":"2016-03-05","format":false,"excerpt":"This is the fifth post in my Missing in PHP7 series. The previous one is about Collections. This is a short post, as there really is not much to explain or motivate. Nullable return types As of PHP7, we have return types at our disposal. Unfortunately, these have some annoying\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.entropywins.wtf\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/posts\/2381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/comments?post=2381"}],"version-history":[{"count":9,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/posts\/2381\/revisions"}],"predecessor-version":[{"id":2651,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/posts\/2381\/revisions\/2651"}],"wp:attachment":[{"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/media?parent=2381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/categories?post=2381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/tags?post=2381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}