Hi Internals,

I'm getting really annoyed at the "Passing null to parameter" problem, and
it happens with new code as well.

I know you have distain for websites that don't use strict types, or static
analysis at the strictest level, but yesterday I was working on a 15 year
old website, it still works well, it uses PHP as a simple scripting
language... because the payment gateway returns a user to the websites
thank-you page with a POST request, and customers leave this page open,
browsers complain (asking to re-submit data), so I just needed to change it
to a GET request, with the order reference in the URL, so I stupidly added
this:

```
if (($_SERVER['REQUEST_METHOD'] ?? '') == 'POST') {
  redirect('/thank-you/?ref=' . urlencode($ref));
}
```

I didn't realise the payment gateway doesn't always provide the order
reference, so the function to get the $ref from the POST request returns
NULL... at the moment that's just an annoying deprecation, but does it
really need to become a fatal error in PHP 9?

Should I be using Rector to update this to `urlencode((string) $ref)`?

Keep in mind, we can still compare NULL to an empty string, concatenate
NULL onto a string, add NULL to an integer/float, and echo/print/sprintf
NULL, we can even use NULL for an array key (as in, it get coerced to an
empty string)... and type coercion happens in other contexts as well, e.g.
passing the string "5" to an integer argument... but NULL will be special,
and cause a fatal type error? really?

Craig

Reply via email to