{"id":1642,"date":"2016-03-05T18:40:48","date_gmt":"2016-03-05T17:40:48","guid":{"rendered":"https:\/\/www.entropywins.wtf\/blog\/?p=1642"},"modified":"2018-07-31T13:02:57","modified_gmt":"2018-07-31T12:02:57","slug":"missing-in-php7-nullable-return-types","status":"publish","type":"post","link":"https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/","title":{"rendered":"Missing in PHP7: Nullable return types"},"content":{"rendered":"<p>This is the fifth post in my <a href=\"https:\/\/www.entropywins.wtf\/blog\/2016\/01\/30\/missing-in-php7\/\">Missing in PHP7 series<\/a>. The previous one is about <a href=\"https:\/\/www.entropywins.wtf\/blog\/2016\/02\/22\/missing-in-php7-collections\/\">Collections<\/a>. This is a short post, as there really is not much to explain or motivate.<\/p>\n<p><strong>Nullable return types<\/strong><\/p>\n<p>As of PHP7, we have <a href=\"http:\/\/php.net\/manual\/en\/functions.returning-values.php#functions.returning-values.type-declaration\">return types<\/a> at our disposal. Unfortunately, these have some annoying limits. One of them I described in my <a href=\"https:\/\/www.entropywins.wtf\/blog\/2016\/02\/22\/missing-in-php7-collections\/\">PHP Collections<\/a> blog post. Another is the lack of nullable return types. This blog post is about the latter.<\/p>\n<p>Take the following code<\/p>\n<pre class=\"lang:php decode:true\">class DoctrineKittenRepository implements KittenRepository {\n    \/**\n     * @param int $kittenId\n     * @return Kitten|null\n     *\/\n    public function getKittenById( int $kittenId ) {\n        try {\n            $kittenOrmEntity = $this-&gt;doctrineThing-&gt;gimmehStuff();\n        }\n        catch ( ORMException $ex ) {\n            return null;\n        }\n\n        if ( $kittenOrmEntity === null ) {\n            return null;\n        }\n\n        return $this-&gt;getKittenFromOrmObject( $kittenOrmEntity );\n    }\n\n    private function getKittenFromOrmObject( OrmKitten ): Kitten {\n        return new Kitten( \/* ... *\/ );\n    }\n}<\/pre>\n<p>This is a <a href=\"https:\/\/lostechies.com\/jimmybogard\/2009\/09\/03\/ddd-repository-implementation-patterns\/\">repository<\/a>, that obtains a kitten from the persistence in some manner (such as using <a href=\"http:\/\/www.doctrine-project.org\/\">Doctine ORM<\/a>). It then returns the kitten as an Entity part of the domain, in this case represented by the <code>Kitten<\/code> class. As you can see, we&#8217;re using a return type hint for the <code>getKittenFromOrmObject<\/code> private method. However for the public method, we&#8217;re prevented from using a return type hint, as it can also return null. This is really unfortunate, as we need to fall back to using documentation instead of code. The IDE I&#8217;m currently using, PhpStrom, manages to add salt to the wound by then requiring all parameters to also be present in the docblock if you don&#8217;t want to get any warnings about them not being there.<\/p>\n<p>It&#8217;d be very nice to be able to do<\/p>\n<pre class=\"lang:php decode:true\">public function getKittenById( int $kittenId ): Kitten|null {}<\/pre>\n<p>Or alternatively<\/p>\n<pre class=\"lang:default decode:true\">public function getKittenById( int $kittenId ): ?Kitten {}<\/pre>\n<p>After <a href=\"http:\/\/stackoverflow.com\/questions\/33608821\/nullable-return-types-in-php7\">asking about this on Stack Overflow<\/a> several months ago, I found out that there is an <a href=\"https:\/\/wiki.php.net\/rfc\/nullable_types\">RFC for nullable return type declarations<\/a>. Unfortunately this appears to not be going anywhere for now. A somewhat related RFC, one for <a href=\"https:\/\/wiki.php.net\/rfc\/void_return_type\">introducing a void return type<\/a>, has on the other hand already been implemented and will land in PHP 7.1.<\/p>\n<p><strong>Nullability in Java<\/strong><\/p>\n<p>I have not often worked with Java in the recent past, though when I did, I always ended up being surprised by it&#8217;s default nullability of types.<\/p>\n<pre class=\"lang:java decode:true\">void someStuff(Kitten kitten) {\n    if (someobject != null) {\n        kitten.doStuff();\n    }\n}<\/pre>\n<p>The caller of <code>someStuff<\/code> can pass in null, which forces null checks in many places, be it like above, or in the form of a <a href=\"http:\/\/c2.com\/cgi\/wiki?GuardClause\">guard clause<\/a> that throw a type error. This is annoying, and indeed, the <a href=\"https:\/\/www.goodreads.com\/book\/show\/3735293-clean-code\">Clean Code book<\/a> even has a chapter on avoiding returning null.<\/p>\n<p>So not all is bad in PHP-land when it comes to nullability \ud83d\ude42<\/p>\n<p><iframe loading=\"lazy\" width=\"853\" height=\"480\" src=\"https:\/\/www.youtube.com\/embed\/bLHL75H_VEM?rel=0\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the fifth post in my Missing in PHP7 series. The previous one is about Collections. This is a&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":true,"_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":[328,410,195,441,197,316,409],"class_list":["post-1642","post","type-post","status-publish","format-standard","hentry","category-programming","tag-clean-code","tag-nullability","tag-php","tag-php7","tag-planet-wikimedia","tag-software-design","tag-type-hinting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Missing in PHP7: Nullable return types - Blog of Jeroen De Dauw<\/title>\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\/2016\/03\/05\/missing-in-php7-nullable-return-types\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Missing in PHP7: Nullable return types - Blog of Jeroen De Dauw\" \/>\n<meta property=\"og:description\" content=\"This is the fifth post in my Missing in PHP7 series. The previous one is about Collections. This is a&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog of Jeroen De Dauw\" \/>\n<meta property=\"article:published_time\" content=\"2016-03-05T17:40:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-07-31T12:02:57+00:00\" \/>\n<meta name=\"author\" content=\"Jeroen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2016\\\/03\\\/05\\\/missing-in-php7-nullable-return-types\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2016\\\/03\\\/05\\\/missing-in-php7-nullable-return-types\\\/\"},\"author\":{\"name\":\"Jeroen\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/#\\\/schema\\\/person\\\/4e2ef14f2ca7dc3a0ac137d1692b66b7\"},\"headline\":\"Missing in PHP7: Nullable return types\",\"datePublished\":\"2016-03-05T17:40:48+00:00\",\"dateModified\":\"2018-07-31T12:02:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2016\\\/03\\\/05\\\/missing-in-php7-nullable-return-types\\\/\"},\"wordCount\":376,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/#\\\/schema\\\/person\\\/4e2ef14f2ca7dc3a0ac137d1692b66b7\"},\"keywords\":[\"Clean Code\",\"Nullability\",\"PHP\",\"PHP7\",\"Planet Wikimedia\",\"Software design\",\"Type hinting\"],\"articleSection\":[\"Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2016\\\/03\\\/05\\\/missing-in-php7-nullable-return-types\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2016\\\/03\\\/05\\\/missing-in-php7-nullable-return-types\\\/\",\"url\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2016\\\/03\\\/05\\\/missing-in-php7-nullable-return-types\\\/\",\"name\":\"Missing in PHP7: Nullable return types - Blog of Jeroen De Dauw\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/#website\"},\"datePublished\":\"2016-03-05T17:40:48+00:00\",\"dateModified\":\"2018-07-31T12:02:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2016\\\/03\\\/05\\\/missing-in-php7-nullable-return-types\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2016\\\/03\\\/05\\\/missing-in-php7-nullable-return-types\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2016\\\/03\\\/05\\\/missing-in-php7-nullable-return-types\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Missing in PHP7: Nullable return types\"}]},{\"@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":"Missing in PHP7: Nullable return types - Blog of Jeroen De Dauw","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\/2016\/03\/05\/missing-in-php7-nullable-return-types\/","og_locale":"en_US","og_type":"article","og_title":"Missing in PHP7: Nullable return types - Blog of Jeroen De Dauw","og_description":"This is the fifth post in my Missing in PHP7 series. The previous one is about Collections. This is a&hellip;","og_url":"https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/","og_site_name":"Blog of Jeroen De Dauw","article_published_time":"2016-03-05T17:40:48+00:00","article_modified_time":"2018-07-31T12:02:57+00:00","author":"Jeroen","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/JeroenDeDauw","twitter_site":"@JeroenDeDauw","twitter_misc":{"Written by":"Jeroen","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/#article","isPartOf":{"@id":"https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/"},"author":{"name":"Jeroen","@id":"https:\/\/www.entropywins.wtf\/blog\/#\/schema\/person\/4e2ef14f2ca7dc3a0ac137d1692b66b7"},"headline":"Missing in PHP7: Nullable return types","datePublished":"2016-03-05T17:40:48+00:00","dateModified":"2018-07-31T12:02:57+00:00","mainEntityOfPage":{"@id":"https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/"},"wordCount":376,"commentCount":2,"publisher":{"@id":"https:\/\/www.entropywins.wtf\/blog\/#\/schema\/person\/4e2ef14f2ca7dc3a0ac137d1692b66b7"},"keywords":["Clean Code","Nullability","PHP","PHP7","Planet Wikimedia","Software design","Type hinting"],"articleSection":["Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/","url":"https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/","name":"Missing in PHP7: Nullable return types - Blog of Jeroen De Dauw","isPartOf":{"@id":"https:\/\/www.entropywins.wtf\/blog\/#website"},"datePublished":"2016-03-05T17:40:48+00:00","dateModified":"2018-07-31T12:02:57+00:00","breadcrumb":{"@id":"https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.entropywins.wtf\/blog\/2016\/03\/05\/missing-in-php7-nullable-return-types\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.entropywins.wtf\/blog\/"},{"@type":"ListItem","position":2,"name":"Missing in PHP7: Nullable return types"}]},{"@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-qu","jetpack-related-posts":[{"id":1898,"url":"https:\/\/www.entropywins.wtf\/blog\/2016\/12\/02\/php-7-1-is-awesome\/","url_meta":{"origin":1642,"position":0},"title":"PHP 7.1 is awesome","author":"Jeroen","date":"2016-12-02","format":false,"excerpt":"PHP 7.1 has been released, bringing some features I was eagerly anticipating and some surprises that had gone under my radar. New iterable pseudo-type This is the feature I'm most exited about, perhaps because I had no clue it was in the works. In short, iterable allows for type hinting\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":1642,"position":1},"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":2381,"url":"https:\/\/www.entropywins.wtf\/blog\/2018\/10\/28\/php-typed-properties\/","url_meta":{"origin":1642,"position":2},"title":"PHP Typed Properties","author":"Jeroen","date":"2018-10-28","format":false,"excerpt":"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\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\/2018\/10\/php-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2018\/10\/php-1.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":1629,"url":"https:\/\/www.entropywins.wtf\/blog\/2016\/02\/22\/missing-in-php7-collections\/","url_meta":{"origin":1642,"position":3},"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":1577,"url":"https:\/\/www.entropywins.wtf\/blog\/2016\/01\/30\/missing-in-php7-function-references\/","url_meta":{"origin":1642,"position":4},"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":2848,"url":"https:\/\/www.entropywins.wtf\/blog\/2022\/01\/30\/value-objects-with-php-8-1\/","url_meta":{"origin":1642,"position":5},"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":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/posts\/1642","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=1642"}],"version-history":[{"count":7,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/posts\/1642\/revisions"}],"predecessor-version":[{"id":2262,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/posts\/1642\/revisions\/2262"}],"wp:attachment":[{"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/media?parent=1642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/categories?post=1642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/tags?post=1642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}