{"id":1396,"date":"2026-08-17T18:00:00","date_gmt":"2026-08-17T17:00:00","guid":{"rendered":"https:\/\/wade.one\/blog\/?p=1396"},"modified":"2026-08-17T18:00:00","modified_gmt":"2026-08-17T17:00:00","slug":"php-8-6-clamp-is-tiny-but-welcome","status":"publish","type":"post","link":"https:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/","title":{"rendered":"PHP 8.6 clamp Is Tiny but Welcome"},"content":{"rendered":"<p>PHP 8.6 is adding a <code>clamp()<\/code> function, and it is the kind of small standard-library change I tend to like. It takes a value plus minimum and maximum bounds, returns the value when it is already inside the range, and otherwise returns the nearest boundary. Nothing clever, just one less helper to rewrite.<\/p>\n<p>The <a href=\"https:\/\/php.watch\/versions\/8.6\/clamp\">PHP 8.6 clamp documentation<\/a> shows the obvious cases: <code>clamp(105, 0, 100)<\/code> returns <code>100<\/code>, while <code>clamp(-5, 0, 100)<\/code> returns <code>0<\/code>. The bounds are inclusive and a minimum greater than the maximum throws a <code>ValueError<\/code>. It works with more than integers and floats, although PHP&#8217;s mixed-type comparison rules mean I would keep its use firmly inside well-typed code.<\/p>\n<p>The practical win is readability. <code>clamp($percentage, 0, 100)<\/code> says what the code is doing more clearly than a nested combination of <code>min()<\/code> and <code>max()<\/code>, especially when somebody has to remember which one goes inside. It is useful for percentages, pagination limits, coordinates, UI values, and plenty of small validation paths.<\/p>\n<p>There is a possible naming collision because <code>clamp<\/code> lives in the global namespace, so projects with an existing helper should check before upgrading. Otherwise this is pleasantly uneventful. PHP does not need every release feature to change how applications are designed. Sometimes removing a familiar five-line helper from thousands of codebases is enough.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP 8.6&#8217;s clamp function removes another tiny helper while keeping range boundaries explicit and readable.<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_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},"jetpack_post_was_ever_published":false},"categories":[28,13],"tags":[216,35,197],"class_list":["post-1396","post","type-post","status-publish","format-standard","hentry","category-php","category-programming","tag-clamp","tag-php","tag-php-8-6"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHP 8.6 clamp Is Tiny but Welcome - wade.one<\/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:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP 8.6 clamp Is Tiny but Welcome - wade.one\" \/>\n<meta property=\"og:description\" content=\"PHP 8.6&#039;s clamp function removes another tiny helper while keeping range boundaries explicit and readable.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/\" \/>\n<meta property=\"og:site_name\" content=\"wade.one\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-17T17:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/Wade-Logo-cropped.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1518\" \/>\n\t<meta property=\"og:image:height\" content=\"1506\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@wadewomersley\" \/>\n<meta name=\"twitter:site\" content=\"@wadewomersley\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated 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\":\"Article\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/08\\\/17\\\/php-8-6-clamp-is-tiny-but-welcome\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/08\\\/17\\\/php-8-6-clamp-is-tiny-but-welcome\\\/\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"PHP 8.6 clamp Is Tiny but Welcome\",\"datePublished\":\"2026-08-17T17:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/08\\\/17\\\/php-8-6-clamp-is-tiny-but-welcome\\\/\"},\"wordCount\":202,\"publisher\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#\\\/schema\\\/person\\\/8b4739f8f8bb2cff5d792d4b8779fcc3\"},\"keywords\":[\"clamp\",\"php\",\"php-8-6\"],\"articleSection\":[\"PHP\",\"Programming\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/08\\\/17\\\/php-8-6-clamp-is-tiny-but-welcome\\\/\",\"url\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/08\\\/17\\\/php-8-6-clamp-is-tiny-but-welcome\\\/\",\"name\":\"PHP 8.6 clamp Is Tiny but Welcome - wade.one\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#website\"},\"datePublished\":\"2026-08-17T17:00:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/08\\\/17\\\/php-8-6-clamp-is-tiny-but-welcome\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/08\\\/17\\\/php-8-6-clamp-is-tiny-but-welcome\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/08\\\/17\\\/php-8-6-clamp-is-tiny-but-welcome\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/wade.one\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP 8.6 clamp Is Tiny but Welcome\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/wade.one\\\/blog\\\/\",\"name\":\"wade.one\",\"description\":\"wade womersley - york based software engineer\",\"publisher\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#\\\/schema\\\/person\\\/8b4739f8f8bb2cff5d792d4b8779fcc3\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wade.one\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#\\\/schema\\\/person\\\/8b4739f8f8bb2cff5d792d4b8779fcc3\",\"name\":\"Wade Womersley\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/200px.png\",\"url\":\"https:\\\/\\\/wade.one\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/200px.png\",\"contentUrl\":\"https:\\\/\\\/wade.one\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/200px.png\",\"width\":202,\"height\":200,\"caption\":\"Wade Womersley\"},\"logo\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/200px.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP 8.6 clamp Is Tiny but Welcome - wade.one","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:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/","og_locale":"en_GB","og_type":"article","og_title":"PHP 8.6 clamp Is Tiny but Welcome - wade.one","og_description":"PHP 8.6's clamp function removes another tiny helper while keeping range boundaries explicit and readable.","og_url":"https:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/","og_site_name":"wade.one","article_published_time":"2026-08-17T17:00:00+00:00","og_image":[{"width":1518,"height":1506,"url":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/Wade-Logo-cropped.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_creator":"@wadewomersley","twitter_site":"@wadewomersley","twitter_misc":{"Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/#article","isPartOf":{"@id":"https:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/"},"author":{"name":"","@id":""},"headline":"PHP 8.6 clamp Is Tiny but Welcome","datePublished":"2026-08-17T17:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/"},"wordCount":202,"publisher":{"@id":"https:\/\/wade.one\/blog\/#\/schema\/person\/8b4739f8f8bb2cff5d792d4b8779fcc3"},"keywords":["clamp","php","php-8-6"],"articleSection":["PHP","Programming"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/","url":"https:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/","name":"PHP 8.6 clamp Is Tiny but Welcome - wade.one","isPartOf":{"@id":"https:\/\/wade.one\/blog\/#website"},"datePublished":"2026-08-17T17:00:00+00:00","breadcrumb":{"@id":"https:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wade.one\/blog\/2026\/08\/17\/php-8-6-clamp-is-tiny-but-welcome\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wade.one\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP 8.6 clamp Is Tiny but Welcome"}]},{"@type":"WebSite","@id":"https:\/\/wade.one\/blog\/#website","url":"https:\/\/wade.one\/blog\/","name":"wade.one","description":"wade womersley - york based software engineer","publisher":{"@id":"https:\/\/wade.one\/blog\/#\/schema\/person\/8b4739f8f8bb2cff5d792d4b8779fcc3"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wade.one\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"https:\/\/wade.one\/blog\/#\/schema\/person\/8b4739f8f8bb2cff5d792d4b8779fcc3","name":"Wade Womersley","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/200px.png","url":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/200px.png","contentUrl":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/200px.png","width":202,"height":200,"caption":"Wade Womersley"},"logo":{"@id":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/200px.png"}}]}},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1374,"url":"https:\/\/wade.one\/blog\/2026\/07\/13\/php-8-6-alpha-1-is-when-teams-should-start-testing\/","url_meta":{"origin":1396,"position":0},"title":"PHP 8.6 Alpha 1 Is When Teams Should Start Testing","author":"","date":"July 13, 2026","format":false,"excerpt":"PHP 8.6 Alpha 1 is not for production, but it is exactly when framework, library, and platform teams should begin compatibility testing.","rel":"","context":"In &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/wade.one\/blog\/category\/php\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1299,"url":"https:\/\/wade.one\/blog\/2026\/05\/11\/php-8-5-nodiscard-is-a-small-api-safety-feature\/","url_meta":{"origin":1396,"position":1},"title":"PHP 8.5 NoDiscard Is a Small API Safety Feature","author":"","date":"May 11, 2026","format":false,"excerpt":"PHP 8.5's NoDiscard attribute gives library and application code a direct way to say that ignoring a return value is probably a bug.","rel":"","context":"In &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/wade.one\/blog\/category\/php\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1106,"url":"https:\/\/wade.one\/blog\/2023\/03\/26\/google-bard-php-developer-viewpoint\/","url_meta":{"origin":1396,"position":2},"title":"Google Bard &#8211; PHP developer viewpoint","author":"Wade","date":"March 26, 2023","format":false,"excerpt":"So I asked Bard to give me a reason to help me as as PHP developer then digged in to each point. Here's the answers and when I tried: Bard can help a PHP developer in a number of ways, including (wht: Code generation:\u00a0Bard can generate code in a variety\u2026","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/wade.one\/blog\/category\/ai\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1140,"url":"https:\/\/wade.one\/blog\/2023\/04\/08\/upgrading-to-php-8-what-you-need-to-know\/","url_meta":{"origin":1396,"position":3},"title":"Upgrading to PHP 8: What You Need to Know","author":"Wade","date":"April 8, 2023","format":false,"excerpt":"Are you considering upgrading your website's PHP version from 7.x to 8.x? While upgrading can offer benefits like improved performance and security, it's important to be aware of potential compatibility issues that may arise. In this post, we'll explore some things to consider before making the switch. Deprecated Functions and\u2026","rel":"","context":"In &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/wade.one\/blog\/category\/php\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1297,"url":"https:\/\/wade.one\/blog\/2026\/05\/09\/php-8-5s-pipe-operator-is-for-readable-code-not-clever-code\/","url_meta":{"origin":1396,"position":4},"title":"PHP 8.5&#8217;s Pipe Operator Is for Readable Code, Not Clever Code","author":"Wade","date":"May 9, 2026","format":false,"excerpt":"The PHP 8.5 pipe operator is useful when it makes data transformations read forwards, but it should not become a new way to hide simple code.","rel":"","context":"In &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/wade.one\/blog\/category\/php\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1300,"url":"https:\/\/wade.one\/blog\/2026\/05\/12\/php-8-5-fatal-error-backtraces-are-an-operations-feature\/","url_meta":{"origin":1396,"position":5},"title":"PHP 8.5 Fatal Error Backtraces Are an Operations Feature","author":"","date":"May 12, 2026","format":false,"excerpt":"PHP 8.5 adding backtraces to fatal errors is a practical production debugging improvement, not just nicer developer output.","rel":"","context":"In &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/wade.one\/blog\/category\/php\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/posts\/1396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/comments?post=1396"}],"version-history":[{"count":1,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/posts\/1396\/revisions"}],"predecessor-version":[{"id":1415,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/posts\/1396\/revisions\/1415"}],"wp:attachment":[{"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/media?parent=1396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/categories?post=1396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/tags?post=1396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}