{"id":7461,"date":"2018-05-11T09:41:54","date_gmt":"2018-05-11T09:41:54","guid":{"rendered":"http:\/\/phpcodez.com\/?p=7461"},"modified":"2018-05-11T09:41:54","modified_gmt":"2018-05-11T09:41:54","slug":"__invoke","status":"publish","type":"post","link":"http:\/\/phpcodez.com\/__invoke\/","title":{"rendered":"__invoke"},"content":{"rendered":"<p>PHP does not allow the passing of function pointers like other languages. Functions are not first class in PHP. Functions being first class mainly means that you can save a function to a variable, and pass it around and execute it at any time.<\/p>\n<p>The __invoke method is a way that PHP can accommodate pseudo-first-class functions.<\/p>\n<p>The __invoke method can be used to pass a class that can act as a closure or a continuation, or simply as a function that you can pass around.<\/p>\n<p>The __invoke() method is called when a script tries to call an object as a function.<\/p>\n<pre>&lt;?php\n class Invoke {\n public function __invoke($x)\n {\n var_dump($x);\n }\n }\n $obj = new Invoke;\n $obj(5);\n?&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>PHP does not allow the passing of function pointers like other languages. Functions are not first class in PHP. Functions being first class mainly means that you can save a function to a variable, and pass it around and execute it at any time. The __invoke method is a way that PHP can accommodate pseudo-first-class &hellip; <a href=\"http:\/\/phpcodez.com\/__invoke\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">__invoke<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[301,314,370],"class_list":["post-7461","post","type-post","status-publish","format-standard","hentry","category-php","tag-magic","tag-methods","tag-php"],"_links":{"self":[{"href":"http:\/\/phpcodez.com\/wp-json\/wp\/v2\/posts\/7461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/phpcodez.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/phpcodez.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/phpcodez.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/phpcodez.com\/wp-json\/wp\/v2\/comments?post=7461"}],"version-history":[{"count":0,"href":"http:\/\/phpcodez.com\/wp-json\/wp\/v2\/posts\/7461\/revisions"}],"wp:attachment":[{"href":"http:\/\/phpcodez.com\/wp-json\/wp\/v2\/media?parent=7461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/phpcodez.com\/wp-json\/wp\/v2\/categories?post=7461"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/phpcodez.com\/wp-json\/wp\/v2\/tags?post=7461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}