rfc:null_coercion_consistency

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
rfc:null_coercion_consistency [2022/04/08 16:38] craigfrancisrfc:null_coercion_consistency [2022/04/09 08:49] – Add user-defined function example craigfrancis
Line 66: Line 66:
 $o[] = htmlspecialchars(false); $o[] = htmlspecialchars(false);
 $o[] = htmlspecialchars(NULL); // Deprecated in 8.1, Fatal Error in 9.0? $o[] = htmlspecialchars(NULL); // Deprecated in 8.1, Fatal Error in 9.0?
 +</code>
 +
 +With user-defined functions, while this does not cause a backwards compatibility issue (details below), it still highlights the coercion inconstancy, and that some type checking is happening in an environment that does not expect type checking:
 +
 +<code php>
 +function user_function(string $s, int $i, float $f, bool $b) {
 +  var_dump($s, $i, $f, $b);
 +  echo "\n";
 +}
 +
 +user_function('1', '1', '1', '1');
 +  // string(1) "1" / int(1) / float(1) / bool(true)
 +
 +user_function(2, 2, 2, 2);
 +  // string(1) "2" / int(2) / float(2) / bool(true)
 +
 +user_function(3.3, 3.3, 3.3, 3.3);
 +  // string(3) "3.3" / int(3) / float(3.3) / bool(true)
 +
 +user_function(false, false, false, false);
 +  // string(0) "" / int(0) / float(0) / bool(false)
 +
 +user_function(NULL, NULL, NULL, NULL);
 +  // Uncaught TypeError x4?
 </code> </code>
  
Line 95: Line 119:
 $value = array_pop($empty_array); $value = array_pop($empty_array);
 $value = mysqli_fetch_row($result); $value = mysqli_fetch_row($result);
-$value = json_decode($json); // Invalid JSON, or deeper than the nesting limit.+$value = json_decode($json); // Invalid JSON, or nesting limit.
 </code> </code>
  
Line 218: Line 242:
 sed -i '' -E 's/(PHPCSHelper::getConfigData)/(string) \1/g' vendor/phpcompatibility/php-compatibility/PHPCompatibility/Sniff.php sed -i '' -E 's/(PHPCSHelper::getConfigData)/(string) \1/g' vendor/phpcompatibility/php-compatibility/PHPCompatibility/Sniff.php
 ./vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility ./vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility
 +
 ./vendor/bin/phpcs -p ./src/ --standard=PHPCompatibility --runtime-set testVersion 8.1 ./vendor/bin/phpcs -p ./src/ --standard=PHPCompatibility --runtime-set testVersion 8.1
 . 1 / 1 (100%) . 1 / 1 (100%)
rfc/null_coercion_consistency.txt · Last modified: 2023/10/18 11:57 by craigfrancis