{"id":14121,"date":"2022-09-19T09:32:31","date_gmt":"2022-09-19T09:32:31","guid":{"rendered":"https:\/\/www.exakat.io\/?page_id=14121"},"modified":"2022-09-19T09:46:18","modified_gmt":"2022-09-19T09:46:18","slug":"phptip-tweets","status":"publish","type":"page","link":"https:\/\/www.exakat.io\/ex\/phptip-tweets\/","title":{"rendered":"PHPtip tweets"},"content":{"rendered":"<h1>PHP tips<\/h1>\n<p>A pot-pourri of 8 PHP tips that were published with <a href=\"https:\/\/twitter.com\/exakat\">@exakat<\/a> account.<\/p>\n<hr \/>\n<p><h2>strict_types exceptions<\/h2>\n<p>strict_types do not apply to #PHP operators, only on to typed structures. <\/p>\n<p>Here, concatenation and interpolation all call __toString(), but not foo(). <\/p>\n<p>As you can see, print() and echo() are safe too, while implode() is not. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.exakat.io\/phptip\/phptip-1.png\" width=\"500\"\/><br \/>\n<a href=\"https:\/\/twitter.com\/exakat\/status\/1571452922042650624\">Tweet<\/a>\n<\/p>\n<hr \/>\n<p><h2>__invoke() and properties and methods<\/h2>\n<p>What does this tricky #PHP code displays?<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.exakat.io\/phptip\/phptip-2.png\" width=\"500\"\/><br \/>\n<a href=\"https:\/\/twitter.com\/exakat\/status\/1569711228301496320\">Tweet<\/a>\n<\/p>\n<hr \/>\n<p><h2>Method syntax and __invoke()<\/h2>\n<p>There are some other cases around instanceof, which are surprising upon first read. <\/p>\n<p>We can use a string in a variable, but not a direct string, a constant nor a ::class.<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.exakat.io\/phptip\/phptip-3.png\" width=\"500\"\/><br \/>\n<a href=\"https:\/\/twitter.com\/exakat\/status\/1569598507329232896\">Tweet<\/a>\n<\/p>\n<hr \/>\n<p><h2>object is not a type<\/h2>\n<p>Such situations always make me smile, yet I am certain several of us will loose time on such a mistake.<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.exakat.io\/phptip\/phptip-4.png\" width=\"500\"\/><br \/>\n<a href=\"https:\/\/twitter.com\/exakat\/status\/1568871734962720770\">Tweet<\/a>\n<\/p>\n<hr \/>\n<p><h2>PHP keywords and namespaces<\/h2>\n<p>I was today&#8217;s old when I realized that #PHP keyword are allowed in namespaces name since #PHP 8.0.<\/p>\n<p>This goes to PHP 8.0 Compatibility ruleset.<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.exakat.io\/phptip\/phptip-5.png\" width=\"500\"\/><br \/>\n<a href=\"https:\/\/twitter.com\/exakat\/status\/1567402995800805378\">Tweet<\/a>\n<\/p>\n<hr \/>\n<p><h2>PHP silent optimisation<\/h2>\n<p>PHP optimisation in action : undefined variables are only reported when they are used. <\/p>\n<p>first is omitted : no operation<br \/>\nsecond is skipped : no need to execute 2nd term<br \/>\nthird is reporting a warning. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.exakat.io\/phptip\/phptip-6.png\" width=\"500\"\/><br \/>\n<a href=\"https:\/\/twitter.com\/exakat\/status\/1563547525688147968\">Tweet<\/a>\n<\/p>\n<hr \/>\n<p><h2>PHP recycles<\/h2>\n<p>TIL PHP recycles the previously created stdClass objects. The following code returns Object #1, until it is stored in $b. <\/p>\n<p>TIL (2) : PHP&#8217;s stdClass&#8217;s constructor omits all its arguments. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.exakat.io\/phptip\/phptip-7.png\" width=\"500\"\/><br \/>\n<a href=\"https:\/\/twitter.com\/exakat\/status\/1557621083615813632\">Tweet<\/a>\n<\/p>\n<hr \/>\n<p><h2>When integer overflows<\/h2>\n<p>Mathematics have the &#8216;Ramanujan Summation&#8217;, where the sum of all integers is -1\/12. <\/p>\n<p>#PHP has the integer overflow. Stay away from the PHP_INT_MAX limits. Valid with (int) or intval() with recent #PHP versions. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.exakat.io\/phptip\/phptip-8.png\" width=\"500\"\/><br \/>\n<a href=\"https:\/\/twitter.com\/exakat\/status\/1552896398152048640\">Tweet<\/a>\n<\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>PHP tips A pot-pourri of 8 PHP tips that were published with @exakat account. strict_types exceptions strict_types do not apply to #PHP operators, only on to typed structures. Here, concatenation and interpolation all call __toString(), but not foo(). As you can see, print() and echo() are safe too, while implode() is not. Tweet __invoke() and [&#8230;]\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-14121","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHPtip tweets - Exakat<\/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.exakat.io\/ex\/phptip-tweets\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHPtip tweets - Exakat\" \/>\n<meta property=\"og:description\" content=\"PHP tips A pot-pourri of 8 PHP tips that were published with @exakat account. strict_types exceptions strict_types do not apply to #PHP operators, only on to typed structures. Here, concatenation and interpolation all call __toString(), but not foo(). As you can see, print() and echo() are safe too, while implode() is not. Tweet __invoke() and [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.exakat.io\/ex\/phptip-tweets\/\" \/>\n<meta property=\"og:site_name\" content=\"Exakat\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-19T09:46:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.exakat.io\/phptip\/phptip-1.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@exakat\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.exakat.io\/ex\/phptip-tweets\/\",\"url\":\"https:\/\/www.exakat.io\/ex\/phptip-tweets\/\",\"name\":\"PHPtip tweets - Exakat\",\"isPartOf\":{\"@id\":\"https:\/\/www.exakat.io\/ex\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.exakat.io\/ex\/phptip-tweets\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.exakat.io\/ex\/phptip-tweets\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.exakat.io\/phptip\/phptip-1.png\",\"datePublished\":\"2022-09-19T09:32:31+00:00\",\"dateModified\":\"2022-09-19T09:46:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.exakat.io\/ex\/phptip-tweets\/#breadcrumb\"},\"inLanguage\":\"ex-EX\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.exakat.io\/ex\/phptip-tweets\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"ex-EX\",\"@id\":\"https:\/\/www.exakat.io\/ex\/phptip-tweets\/#primaryimage\",\"url\":\"https:\/\/www.exakat.io\/phptip\/phptip-1.png\",\"contentUrl\":\"https:\/\/www.exakat.io\/phptip\/phptip-1.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.exakat.io\/ex\/phptip-tweets\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.exakat.io\/ex\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHPtip tweets\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.exakat.io\/ex\/en\/#website\",\"url\":\"https:\/\/www.exakat.io\/ex\/en\/\",\"name\":\"Exakat\",\"description\":\"Bring Quality to your PHP Projects\",\"publisher\":{\"@id\":\"https:\/\/www.exakat.io\/ex\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.exakat.io\/ex\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ex-EX\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.exakat.io\/ex\/en\/#organization\",\"name\":\"Exakat SAS\",\"alternateName\":\"Exakat\",\"url\":\"https:\/\/www.exakat.io\/ex\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ex-EX\",\"@id\":\"https:\/\/www.exakat.io\/ex\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.exakat.io\/wp-content\/uploads\/2014\/12\/cropped-cropped-logo-exakat-small.png\",\"contentUrl\":\"https:\/\/www.exakat.io\/wp-content\/uploads\/2014\/12\/cropped-cropped-logo-exakat-small.png\",\"width\":512,\"height\":512,\"caption\":\"Exakat SAS\"},\"image\":{\"@id\":\"https:\/\/www.exakat.io\/ex\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/exakat\",\"https:\/\/phpc.social\/@Exakat\",\"https:\/\/bsky.app\/profile\/dseguy.bsky.social\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHPtip tweets - Exakat","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.exakat.io\/ex\/phptip-tweets\/","og_locale":"en_US","og_type":"article","og_title":"PHPtip tweets - Exakat","og_description":"PHP tips A pot-pourri of 8 PHP tips that were published with @exakat account. strict_types exceptions strict_types do not apply to #PHP operators, only on to typed structures. Here, concatenation and interpolation all call __toString(), but not foo(). As you can see, print() and echo() are safe too, while implode() is not. Tweet __invoke() and [...]","og_url":"https:\/\/www.exakat.io\/ex\/phptip-tweets\/","og_site_name":"Exakat","article_modified_time":"2022-09-19T09:46:18+00:00","og_image":[{"url":"https:\/\/www.exakat.io\/phptip\/phptip-1.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_site":"@exakat","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.exakat.io\/ex\/phptip-tweets\/","url":"https:\/\/www.exakat.io\/ex\/phptip-tweets\/","name":"PHPtip tweets - Exakat","isPartOf":{"@id":"https:\/\/www.exakat.io\/ex\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.exakat.io\/ex\/phptip-tweets\/#primaryimage"},"image":{"@id":"https:\/\/www.exakat.io\/ex\/phptip-tweets\/#primaryimage"},"thumbnailUrl":"https:\/\/www.exakat.io\/phptip\/phptip-1.png","datePublished":"2022-09-19T09:32:31+00:00","dateModified":"2022-09-19T09:46:18+00:00","breadcrumb":{"@id":"https:\/\/www.exakat.io\/ex\/phptip-tweets\/#breadcrumb"},"inLanguage":"ex-EX","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.exakat.io\/ex\/phptip-tweets\/"]}]},{"@type":"ImageObject","inLanguage":"ex-EX","@id":"https:\/\/www.exakat.io\/ex\/phptip-tweets\/#primaryimage","url":"https:\/\/www.exakat.io\/phptip\/phptip-1.png","contentUrl":"https:\/\/www.exakat.io\/phptip\/phptip-1.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.exakat.io\/ex\/phptip-tweets\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.exakat.io\/ex\/"},{"@type":"ListItem","position":2,"name":"PHPtip tweets"}]},{"@type":"WebSite","@id":"https:\/\/www.exakat.io\/ex\/en\/#website","url":"https:\/\/www.exakat.io\/ex\/en\/","name":"Exakat","description":"Bring Quality to your PHP Projects","publisher":{"@id":"https:\/\/www.exakat.io\/ex\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.exakat.io\/ex\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ex-EX"},{"@type":"Organization","@id":"https:\/\/www.exakat.io\/ex\/en\/#organization","name":"Exakat SAS","alternateName":"Exakat","url":"https:\/\/www.exakat.io\/ex\/en\/","logo":{"@type":"ImageObject","inLanguage":"ex-EX","@id":"https:\/\/www.exakat.io\/ex\/en\/#\/schema\/logo\/image\/","url":"https:\/\/www.exakat.io\/wp-content\/uploads\/2014\/12\/cropped-cropped-logo-exakat-small.png","contentUrl":"https:\/\/www.exakat.io\/wp-content\/uploads\/2014\/12\/cropped-cropped-logo-exakat-small.png","width":512,"height":512,"caption":"Exakat SAS"},"image":{"@id":"https:\/\/www.exakat.io\/ex\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/exakat","https:\/\/phpc.social\/@Exakat","https:\/\/bsky.app\/profile\/dseguy.bsky.social"]}]}},"_links":{"self":[{"href":"https:\/\/www.exakat.io\/ex\/wp-json\/wp\/v2\/pages\/14121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.exakat.io\/ex\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.exakat.io\/ex\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.exakat.io\/ex\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.exakat.io\/ex\/wp-json\/wp\/v2\/comments?post=14121"}],"version-history":[{"count":4,"href":"https:\/\/www.exakat.io\/ex\/wp-json\/wp\/v2\/pages\/14121\/revisions"}],"predecessor-version":[{"id":14125,"href":"https:\/\/www.exakat.io\/ex\/wp-json\/wp\/v2\/pages\/14121\/revisions\/14125"}],"wp:attachment":[{"href":"https:\/\/www.exakat.io\/ex\/wp-json\/wp\/v2\/media?parent=14121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}