Skip to content

Instantly share code, notes, and snippets.

@croensch
Last active December 8, 2022 21:48
Show Gist options
  • Save croensch/c7d172416757dac000af11742b00b3b6 to your computer and use it in GitHub Desktop.
Save croensch/c7d172416757dac000af11742b00b3b6 to your computer and use it in GitHub Desktop.
PHP haltig engine warnings to PHPStan levels
<?php
/**
* https://wiki.php.net/rfc/engine_warnings
*/
// old-Level: Message > new-Level | phpstan-level
#$o = null;
// Warning: Creating default object from empty value > Error: Attempt to assign property "p" on null | 2
#$o->p = 0;
// Notice: Trying to get property '%s' of non-object > Warning | 2
#echo (0)->p;
#class std {}
#$x = new std;
// Notice: Undefined property: %s::$%s > Warning | 2 (but not for stdClass/object)
#print_r($x->y);
#$o = 0;
// Warning: Cannot use a scalar value as an array > Error | 3
#$o[0] = 0;
// Notice: Trying to access array offset on value of type %s > Warning | 3
#echo (0)[0];
// Warning: Invalid argument supplied for foreach() = Warning | 3
#foreach ("" as $c) {}
// Notice: Object of class stdClass could not be converted to int = Notice | 2
print_r((new stdClass) == 1);
// Warning: A non-numeric value encountered > ERROR | 2
#echo 0 + "1s";
$x = '1';
// Warning: Cannot assign an empty string to a string offset > Error | ?
$x[0] = '';
/* Warning: count() Parameter muste be an array or an object that implements Countable > Error | 5 */
#count(new stdClass);
/* Error: Call to a member function %s() on null = Error | 2 */
#(null)->m();
# PHP 7.1 < Error: [] operator not supported for strings | 3
#$x = '';
#$x[] = null;
#print_r($x);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment