Skip to content
Wade Womersley

wade.one

wade womersley – york based software engineer

  • Home
  • 2026
  • May
  • 11
  • PHP 8.5 NoDiscard Is a Small API Safety Feature

PHP 8.5 NoDiscard Is a Small API Safety Feature

Posted on May 11, 2026 By
PHP, Programming

#[\NoDiscard] is not the biggest PHP 8.5 feature, but it is one I expect to age well. A lot of production bugs come from a function returning something important and the caller quietly ignoring it. Sometimes that is harmless. Sometimes it means a lock was not acquired, a validation result was dropped, or an immutable object update never actually got used.

The PHP manual now documents the NoDiscard attribute, and the RFC describes it as a way to mark return values as important. PHP 8.5 can warn when the return value is discarded, which brings a useful static-analysis idea closer to the language itself.

I would use this sparingly. If every non-void function gets marked, the signal gets noisy and developers learn to ignore it. It makes more sense on methods where dropping the result is almost always wrong: immutable with*() methods, validation helpers, lock attempts, transaction-style APIs, parsing results, or functions that return a changed copy rather than modifying in place.

This is the kind of feature that improves code review more than code writing. It turns “remember to use the returned value” from tribal knowledge into something the code can say for itself. That is a good trade: a little extra metadata in the API, fewer silent mistakes later.

Share:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit

Related

Comments

comments

Tags: api-design nodiscard php php-8-5

Post navigation

❮ Previous Post: PHP 8.5 Clone With Makes Value Objects Less Annoying
Next Post: PHP 8.5 Fatal Error Backtraces Are an Operations Feature ❯

You may also like

Programming
Reset MySQL root password if you forgot it #mysql
April 12, 2010
Programming
Read the PostgreSQL Query Plan Before Adding Another Index
October 15, 2026
Programming
PHP 5.4 Unofficial Ubuntu apt-get available
March 11, 2012
Programming
I Trust Boring Infrastructure More Than Clever Infrastructure
April 4, 2026
  • AI
  • artificial intelligence
  • Ego-centric
  • Events
  • Films
  • Food
  • Gaming
  • Gym
  • Hardware
  • Holidays
  • News
  • PHP
  • Programming
  • Random Stuff
  • Reviews
  • Science
  • SEO
  • Software
  • Software Engineer
  • Support
  • Uncategorized
  • Work

Categories

  • AI
  • artificial intelligence
  • Ego-centric
  • Events
  • Films
  • Food
  • Gaming
  • Gym
  • Hardware
  • Holidays
  • News
  • PHP
  • Programming
  • Random Stuff
  • Reviews
  • Science
  • SEO
  • Software
  • Software Engineer
  • Support
  • Uncategorized
  • Work

Archives

  • November 2026
  • October 2026
  • August 2026
  • July 2026
  • June 2026
  • May 2026
  • April 2026
  • March 2026
  • August 2023
  • April 2023
  • March 2023
  • April 2016
  • October 2015
  • July 2015
  • June 2015
  • May 2015
  • March 2015
  • February 2015
  • January 2015
  • October 2014
  • December 2013
  • September 2013
  • June 2013
  • October 2012
  • May 2012
  • March 2012
  • February 2012
  • April 2011
  • March 2011
  • October 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009

Copyright © 2026 wade.one.

Theme: Oceanly News Dark by ScriptsTown