When usinc `arc diff` in PHP 8.2 this exception can happen:
```
strlen(): Passing null to parameter #1 ($string) of type string is deprecated
```
```
$ arc diff --trace
Running unit tests...
>>> [57] (+50,812) <connect> phabricator_config
<<< [57] (+50,813) <connect> 571 us
>>> [58] (+50,813) <query> SELECT * FROM `phabricator_config`.`config_entry` WHERE namespace = 'default' AND isDeleted = 0
<<< [58] (+50,813) <query> 165 us
[2023-03-24 19:51:00] EXCEPTION: (RuntimeException) strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [<arcanist>/src/error/PhutilErrorHandler.php:261]
arcanist(head=master, ref.master=9e1bb955fac9), phorge(head=arcpatch-D25066_workboard_refactor, ref.master=c6f56b8221ba, ref.arcpatch-D25066_workboard_refactor=6c38649ba830)
#0 PhutilErrorHandler::handleError(integer, string, string, integer) called at [<phorge>/src/infrastructure/env/PhabricatorEnv.php:128]
#1 PhabricatorEnv::initializeCommonEnvironment(boolean) called at [<phorge>/src/infrastructure/env/PhabricatorEnv.php:75]
#2 PhabricatorEnv::initializeScriptEnvironment(boolean) called at [<phorge>/scripts/init/lib.php:26]
#3 init_phabricator_script(array) called at [<phorge>/scripts/init/init-script.php:7]
#4 require_once(string) called at [<phorge>/scripts/__init_script__.php:3]
#5 require_once(string) called at [<phorge>/src/infrastructure/testing/PhabricatorTestCase.php:62]
#6 PhabricatorTestCase::willRunTestCases(array) called at [<arcanist>/src/unit/engine/PhutilUnitTestEngine.php:64]
#7 PhutilUnitTestEngine::run() called at [<arcanist>/src/unit/engine/ArcanistConfigurationDrivenUnitTestEngine.php:148]
#8 ArcanistConfigurationDrivenUnitTestEngine::run() called at [<arcanist>/src/workflow/ArcanistUnitWorkflow.php:170]
#9 ArcanistUnitWorkflow::run() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:1231]
#10 ArcanistDiffWorkflow::runUnit() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:1133]
#11 ArcanistDiffWorkflow::runLintUnit() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:363]
#12 ArcanistDiffWorkflow::run() called at [<arcanist>/scripts/arcanist.php:427]
<<< [1] (+51,023) <exec> 51,023,728 us
```
== About PhabricatorEnv::getEnvConfig() ==
The method `PhabricatorEnv::getEnvConfig()` returns a mixed value. The problem is, most of our checks are something like this:
```lang=php
public function newDefaultEmailAddress() {
$test = PhabricatorEnv::getEnvConfig('test');
if (strlen($test)) {
```
Note that checking `strlen()` had sense to both assume that:
- it was a string
- it is not an empty string
Note that, they had not used just `is_empty()` generally for that, since it's broken, as it considers the string `"0"` as empty for some very weird reasons.
Note that, we use `strlen()` to just check if it's zero, but `strlen()` is slower than `is_empty()` - since `strlen()` counts every single character, while `is_empty()` just tells whether it is empty or not.
Note that, for the following case, the natural change should be this one now, that is literally the raw fix:
```lang=diff
public function newDefaultEmailAddress() {
$test = PhabricatorEnv::getEnvConfig('test');
- if (strlen($test)) {
+ if ($test != null && strlen($test)) {
```
But, this is not efficient. Logically, this should be the correct check but it's damn long:
```lang=diff
public function newDefaultEmailAddress() {
$test = PhabricatorEnv::getEnvConfig('test');
- if (strlen($test)) {
+ if ($test !== null && is_string( $text ) && $text !== '') {
```
So, we could introduce this simple wrapper method:
```lang=php
public static function getEnvConfigString($key) {
return (string) self::getEnvConfig($key);
}
```
The above method is very efficient since, in the base case, any long string is just returned as-is. The NULL is then converted as '' (very quick operation).
In this way, every line of source code can eliminate two tests, assuming that the string is never NULL and it's always a string, and we can eliminate the need of counting every character. Example:
```lang=diff
public function newDefaultEmailAddress() {
- $test = PhabricatorEnv::getEnvConfig('test');
+ $test = PhabricatorEnv::getEnvConfigString('test');
if ($test !== '') {
```