{"id":2092,"date":"2017-10-09T07:16:12","date_gmt":"2017-10-09T06:16:12","guid":{"rendered":"https:\/\/www.entropywins.wtf\/blog\/?p=2092"},"modified":"2018-07-31T12:58:06","modified_gmt":"2018-07-31T11:58:06","slug":"yield-in-phpunit-data-providers","status":"publish","type":"post","link":"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/09\/yield-in-phpunit-data-providers\/","title":{"rendered":"Yield in PHPUnit data providers"},"content":{"rendered":"<p>Initially I started creating a general post about <a href=\"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/16\/introduction-to-iterators-and-generators-in-php\/\">PHP Generators<\/a>, a feature introduced in PHP 5.5. However since I keep failing to come up with good examples for some cool ways to use Generators, I decided to do this mini post focusing on one such cool usage.<\/p>\n<p><strong>PHPUnit data providers<\/strong><\/p>\n<p>A commonly used <a href=\"http:\/\/phpunit.de\/\">PHPUnit<\/a> feature is <a href=\"https:\/\/phpunit.de\/manual\/current\/en\/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers\">data providers<\/a>. In a data provider you specify a list of argument lists, and the test methods that use the data provider get called once for each argument list.<\/p>\n<p>Often data providers are created with an array variable in which the argument lists get stuffed. Example (including poor naming):<\/p>\n<pre class=\"lang:php decode:true\">\/**\n * @dataProvider provideUserInfo\n *\/\nfunction testSomeStuff( string $userName, int $userAge ) {}\n\nfunction provideUserInfo() {\n    $return = [];\n\n    $return[] = [ 'Such Name', 42 ];\n    $return[] = [ 'Very Name', 23 ];\n    $return['Named parameter set'] = [ 'So Name', 1337 ];\n\n    return $return;\n}<\/pre>\n<p>The not so nice thing here is that you have a variable (explicit state) and you modify it (mutable state). A more functional approach is to just return an array that holds the argument lists directly. However if your argument list creation is more complex than in this example, requiring state, this might not work. And when such state is required, you end up with more complexity and a higher chance that the <code>$return<\/code> variable will bite you.<\/p>\n<p><strong>Using yield<\/strong><\/p>\n<p>What you might not have realized is that data providers do not need to return an array. They need to return an <code>iterable<\/code>, so they can also return an <code>Iterator<\/code>, and by extension, a <code>Generator<\/code>. This means you can write the above data provider as follows:<\/p>\n<pre class=\"lang:php decode:true\">function provideUserInfo() {\n    yield [ 'Such Name', 42 ];\n    yield [ 'Very Name', 23 ];\n    yield 'Named parameter set' =&gt; [ 'So Name', 1337 ];\n}<\/pre>\n<p>No explicit state to be seen!<\/p>\n<p>Update: my <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> is now live \ud83d\ude42<\/p>\n<p>See also: <a href=\"https:\/\/www.entropywins.wtf\/blog\/2016\/05\/13\/5-ways-to-write-better-mocks\/\">5 ways to write better mocks<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Initially I started creating a general post about PHP Generators, a feature introduced in PHP 5.5. However since I keep&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":[328,374,354,195,196,197,257],"class_list":["post-2092","post","type-post","status-publish","format-standard","hentry","category-programming","tag-clean-code","tag-generators","tag-iterator","tag-php","tag-phpunit","tag-planet-wikimedia","tag-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Yield in PHPUnit data providers - 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\/2017\/10\/09\/yield-in-phpunit-data-providers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Yield in PHPUnit data providers - Blog of Jeroen De Dauw\" \/>\n<meta property=\"og:description\" content=\"Initially I started creating a general post about PHP Generators, a feature introduced in PHP 5.5. However since I keep&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/09\/yield-in-phpunit-data-providers\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog of Jeroen De Dauw\" \/>\n<meta property=\"article:published_time\" content=\"2017-10-09T06:16:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-07-31T11:58:06+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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2017\\\/10\\\/09\\\/yield-in-phpunit-data-providers\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2017\\\/10\\\/09\\\/yield-in-phpunit-data-providers\\\/\"},\"author\":{\"name\":\"Jeroen\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/#\\\/schema\\\/person\\\/4e2ef14f2ca7dc3a0ac137d1692b66b7\"},\"headline\":\"Yield in PHPUnit data providers\",\"datePublished\":\"2017-10-09T06:16:12+00:00\",\"dateModified\":\"2018-07-31T11:58:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2017\\\/10\\\/09\\\/yield-in-phpunit-data-providers\\\/\"},\"wordCount\":256,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/#\\\/schema\\\/person\\\/4e2ef14f2ca7dc3a0ac137d1692b66b7\"},\"keywords\":[\"Clean Code\",\"Generators\",\"Iterator\",\"PHP\",\"PHPUnit\",\"Planet Wikimedia\",\"Testing\"],\"articleSection\":[\"Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2017\\\/10\\\/09\\\/yield-in-phpunit-data-providers\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2017\\\/10\\\/09\\\/yield-in-phpunit-data-providers\\\/\",\"url\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2017\\\/10\\\/09\\\/yield-in-phpunit-data-providers\\\/\",\"name\":\"Yield in PHPUnit data providers - Blog of Jeroen De Dauw\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/#website\"},\"datePublished\":\"2017-10-09T06:16:12+00:00\",\"dateModified\":\"2018-07-31T11:58:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2017\\\/10\\\/09\\\/yield-in-phpunit-data-providers\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2017\\\/10\\\/09\\\/yield-in-phpunit-data-providers\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/2017\\\/10\\\/09\\\/yield-in-phpunit-data-providers\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.entropywins.wtf\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Yield in PHPUnit data providers\"}]},{\"@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":"Yield in PHPUnit data providers - 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\/2017\/10\/09\/yield-in-phpunit-data-providers\/","og_locale":"en_US","og_type":"article","og_title":"Yield in PHPUnit data providers - Blog of Jeroen De Dauw","og_description":"Initially I started creating a general post about PHP Generators, a feature introduced in PHP 5.5. However since I keep&hellip;","og_url":"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/09\/yield-in-phpunit-data-providers\/","og_site_name":"Blog of Jeroen De Dauw","article_published_time":"2017-10-09T06:16:12+00:00","article_modified_time":"2018-07-31T11:58:06+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":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/09\/yield-in-phpunit-data-providers\/#article","isPartOf":{"@id":"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/09\/yield-in-phpunit-data-providers\/"},"author":{"name":"Jeroen","@id":"https:\/\/www.entropywins.wtf\/blog\/#\/schema\/person\/4e2ef14f2ca7dc3a0ac137d1692b66b7"},"headline":"Yield in PHPUnit data providers","datePublished":"2017-10-09T06:16:12+00:00","dateModified":"2018-07-31T11:58:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/09\/yield-in-phpunit-data-providers\/"},"wordCount":256,"commentCount":1,"publisher":{"@id":"https:\/\/www.entropywins.wtf\/blog\/#\/schema\/person\/4e2ef14f2ca7dc3a0ac137d1692b66b7"},"keywords":["Clean Code","Generators","Iterator","PHP","PHPUnit","Planet Wikimedia","Testing"],"articleSection":["Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.entropywins.wtf\/blog\/2017\/10\/09\/yield-in-phpunit-data-providers\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/09\/yield-in-phpunit-data-providers\/","url":"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/09\/yield-in-phpunit-data-providers\/","name":"Yield in PHPUnit data providers - Blog of Jeroen De Dauw","isPartOf":{"@id":"https:\/\/www.entropywins.wtf\/blog\/#website"},"datePublished":"2017-10-09T06:16:12+00:00","dateModified":"2018-07-31T11:58:06+00:00","breadcrumb":{"@id":"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/09\/yield-in-phpunit-data-providers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.entropywins.wtf\/blog\/2017\/10\/09\/yield-in-phpunit-data-providers\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/09\/yield-in-phpunit-data-providers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.entropywins.wtf\/blog\/"},{"@type":"ListItem","position":2,"name":"Yield in PHPUnit data providers"}]},{"@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-xK","jetpack-related-posts":[{"id":904,"url":"https:\/\/www.entropywins.wtf\/blog\/2010\/07\/18\/mediawiki-testing-with-phpunit\/","url_meta":{"origin":2092,"position":0},"title":"MediaWiki testing with PHPUnit","author":"Jeroen","date":"2010-07-18","format":false,"excerpt":"I figured having some unit tests for Maps, the MediaWiki extension to work with geographical data and display it by embedding dynamic maps into your articles, would be beneficial to it's quality. It's pretty hard to try cover all possible use cases with manual tests, and consumes a lot of\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.entropywins.wtf\/blog\/category\/programming\/"},"img":{"alt_text":"PEAR logo","src":"https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2010\/07\/pearsmall.gif?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1693,"url":"https:\/\/www.entropywins.wtf\/blog\/2016\/05\/13\/5-ways-to-write-better-mocks\/","url_meta":{"origin":2092,"position":1},"title":"5 ways to write better mocks","author":"Jeroen","date":"2016-05-13","format":false,"excerpt":"In this post I share 5 easy ways to write better mocks that I picked up over the years. These will help you write tests that break less, are easier to read, are more IDE friendly, and are easier to refactor. The focus is on PHPUnit and PHP, yet most\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":2027,"url":"https:\/\/www.entropywins.wtf\/blog\/2017\/04\/25\/php-development-with-docker\/","url_meta":{"origin":2092,"position":2},"title":"PHP development with Docker","author":"Jeroen","date":"2017-04-25","format":false,"excerpt":"I'm the kind of dev that dreads configuring webservers and that rather does not have to put up with random ops stuff before being able to get work done. Docker is one of those things I've never looked into, cause clearly it's evil annoying boring evil confusing evil ops stuff.\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":2106,"url":"https:\/\/www.entropywins.wtf\/blog\/2017\/10\/16\/introduction-to-iterators-and-generators-in-php\/","url_meta":{"origin":2092,"position":3},"title":"Introduction to Iterators and Generators in PHP","author":"Jeroen","date":"2017-10-16","format":false,"excerpt":"In this post I demonstrate an effective way to create iterators and generators in PHP and provide an example of a scenario in which using them makes sense. Generators have been around since PHP 5.5, and iterators have been around since the Planck epoch. Even so, a lot of PHP\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\/2017\/10\/D8Pl1XwX4AEaU5H.jpeg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2017\/10\/D8Pl1XwX4AEaU5H.jpeg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2017\/10\/D8Pl1XwX4AEaU5H.jpeg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2017\/10\/D8Pl1XwX4AEaU5H.jpeg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2017\/10\/D8Pl1XwX4AEaU5H.jpeg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/www.entropywins.wtf\/blog\/wp-content\/uploads\/2017\/10\/D8Pl1XwX4AEaU5H.jpeg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":2271,"url":"https:\/\/www.entropywins.wtf\/blog\/2018\/08\/01\/clean-architecture-usecase-tests\/","url_meta":{"origin":2092,"position":4},"title":"Clean Architecture: UseCase tests","author":"Jeroen","date":"2018-08-01","format":false,"excerpt":"When creating an application that follows The Clean Architecture you end up with a number of UseCases that hold your application logic. In this blog post I outline a testing pattern for effectively testing these UseCases and avoiding common pitfalls. Testing UseCases A UseCase contains the application logic for a\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":1577,"url":"https:\/\/www.entropywins.wtf\/blog\/2016\/01\/30\/missing-in-php7-function-references\/","url_meta":{"origin":2092,"position":5},"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":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/posts\/2092","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=2092"}],"version-history":[{"count":6,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/posts\/2092\/revisions"}],"predecessor-version":[{"id":2249,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/posts\/2092\/revisions\/2249"}],"wp:attachment":[{"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/media?parent=2092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/categories?post=2092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.entropywins.wtf\/blog\/wp-json\/wp\/v2\/tags?post=2092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}