Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we still need 'declare(strict_types=1)' in PHP 8.1?

Tags:

php

As asked above, are we still required to put declare(strict_types=1) in the header of every single program in our projects in PHP 8.1?

I'd love for it to be just strict all the time.

like image 394
MichaelICE Avatar asked Sep 13 '25 00:09

MichaelICE


1 Answers

Yes! Tested with PHP 8.1.7 there is still a difference.

See this question to understand what the strict types do.

New in PHP 8.1: when a float value is coerced to an int value implicitly, like in the example from the other question, a deprecation notice is triggered: PHP Deprecated: Implicit conversion from float 1.4 to int loses precision. More details

Further reading

  • What do strict types do in PHP?
  • PHP 8.1: Implicit incompatible float to int conversion is deprecated
like image 172
nickel715 Avatar answered Sep 15 '25 14:09

nickel715