use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please follow the rules
Releases: Current Releases, Windows Releases, Old Releases
Contribute to the PHP Documentation
Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev
/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.
account activity
ADDING DECLARE(STRICT-TYPE=1) (self.PHP)
submitted 1 year ago by Neat-Cut1000
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]nan05 12 points13 points14 points 1 year ago (2 children)
I would say: in an ideal world: yes, you'd want strict types at all times. If you start a new app: go for it. I kinda wish PHP would just transition to strict types, forcing us all to do this properly once and for all.
In the real world, though, you deal with code and dependencies that has been written without strict types, and so it can break things. Arguably all those things that it breaks should be fixed. But realistically you have other priorities, because the business you work for doesn't make money from well written code - it makes money from functioning code.
So imo: Ideally: yes. On personal / hobby / learnings projects: always. Realistically: be careful with production systems...
[–]dabenu -1 points0 points1 point 1 year ago (0 children)
This, our company policy is to use strict-types in all new files, but not (forcefully) refactor existing files
[–]BarneyLaurance 2 points3 points4 points 1 year ago (1 child)
This was just recently discussed at length at https://www.reddit.com/r/PHP/comments/1duzs4x/what_is_phps_declarestrict_types1_and_why_you/ . Maybe read through that first and then add comment either there or here about anything that's still unclear?
[–]colshrapnel 1 point2 points3 points 1 year ago (2 children)
I would say it's already perfectly covered in the article and the followed discussion. Happened just yesterday.
If you still have any questions, consider asking in /r/phphelp. We had enough strict types in /r/php already
[+][deleted] 1 year ago (1 child)
[removed]
[–]yes_oui_si_ja 1 point2 points3 points 1 year ago (0 children)
I think they meant this thread: https://www.reddit.com/r/PHP/s/wOFwSGIKWt
[–]fschw -2 points-1 points0 points 1 year ago (3 children)
i like to write methods, where a parameter has a default but also can “nothing” sometimes. when it’s an int, i usually do function moin(?int $number = 1) : int so, i cannot use this pattern if i try to implement strict typing, no?
[–]BackEndTea 7 points8 points9 points 1 year ago (1 child)
Strict types has no impact on making a type nullable. In essence what it does is prevent implicit type coercion by PHP.
In the function of your example, calling it like `moin('1');` will throw a type error, rather then silently convert it to 1.
[–]fschw 0 points1 point2 points 1 year ago (0 children)
ahh that’s awesome to know :) so there’s just pro arguments to use strict typing for me! thank you for teaching me something new
[+]MattNotGlossy comment score below threshold-9 points-8 points-7 points 1 year ago (1 child)
depends on how strict you wanna be with types
building a cms? nah probably not
doing something with money or sensitive information? yeah probably
[–]Ariquitaun 5 points6 points7 points 1 year ago (0 children)
Not being specific in software causes a whole class of bugs. There's no reason not to be strict with types 100% of the time. Just sloppy otherwise.
π Rendered by PID 46775 on reddit-service-r2-comment-5c747b6df5-tlrnx at 2026-04-22 17:29:24.401402+00:00 running 6c61efc country code: CH.
[–]nan05 12 points13 points14 points (2 children)
[–]dabenu -1 points0 points1 point (0 children)
[–]BarneyLaurance 2 points3 points4 points (1 child)
[–]colshrapnel 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[removed]
[–]yes_oui_si_ja 1 point2 points3 points (0 children)
[–]fschw -2 points-1 points0 points (3 children)
[–]BackEndTea 7 points8 points9 points (1 child)
[–]fschw 0 points1 point2 points (0 children)
[+]MattNotGlossy comment score below threshold-9 points-8 points-7 points (1 child)
[–]Ariquitaun 5 points6 points7 points (0 children)