Skip to content

Commit

Permalink
Merge pull request #3015 from TysonAndre/catch-notice
Browse files Browse the repository at this point in the history
Handle deprecation notices from php-ast and composer libraries
  • Loading branch information
TysonAndre committed Jul 27, 2019
2 parents 7114691 + 7cf7b56 commit 6483476
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 27 deletions.
1 change: 1 addition & 0 deletions .phan/config.php
Expand Up @@ -483,6 +483,7 @@
'PHPDocToRealTypesPlugin', // suggests replacing (at)return void with `: void` in the declaration, etc.
'PHPDocRedundantPlugin',
'PreferNamespaceUsePlugin',
'EmptyStatementListPlugin',

// This should only be enabled if the code being analyzed contains Phan plugins.
'PhanSelfCheckPlugin',
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Expand Up @@ -39,6 +39,7 @@ Plugins:
Bug fixes:
+ Treat `Foo::class` as a reference to the class/interface/trait `Foo` (#2945)
+ Fix crash for `(real)` cast in php 7.4. (#3012)
+ Work around crash due to deprecation notices in composer dependencies in php 7.4

Jul 17 2019, Phan 2.2.6
-----------------------
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -122,10 +122,10 @@ A simple `.phan/config.php` file might look something like the following.
*/
return [

// Supported values: '7.0', '7.1', '7.2', '7.3', null.
// If this is set to null,
// Supported values: `'5.6'`, `'7.0'`, `'7.1'`, `'7.2'`, `'7.3'`, `'7.4'`, `null`.
// If this is set to `null`,
// then Phan assumes the PHP version which is closest to the minor version
// of the php executable used to execute phan.
// of the php executable used to execute Phan.
"target_php_version" => null,

// A list of directories that should be parsed for class and
Expand Down
36 changes: 18 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/Phan/AST/Parser.php
Expand Up @@ -123,8 +123,11 @@ private static function parseCodeHandlingDeprecation(CodeBase $code_base, Contex
// and those errors might mess up language servers, etc. if ever printed to stdout
$original_error_reporting = error_reporting();
error_reporting($original_error_reporting & ~\E_COMPILE_WARNING);
$__no_echo_phan_errors = static function (int $unused_errno, string $errstr, string $unused_errfile, int $errline) use ($code_base, $context) : bool {
// Catch errors such as E_DEPRECATION in php 7.4 for the (real) cast.
$__no_echo_phan_errors = static function (int $errno, string $errstr, string $unused_errfile, int $errline) use ($code_base, $context) : bool {
if ($errno == E_DEPRECATED && preg_match('/Version.*is deprecated/i', $errstr)) {
return false;
}
// Catch errors such as E_DEPRECATED in php 7.4 for the (real) cast.
Issue::maybeEmit(
$code_base,
$context,
Expand Down
15 changes: 12 additions & 3 deletions src/Phan/Bootstrap.php
Expand Up @@ -181,9 +181,12 @@ function phan_error_handler(int $errno, string $errstr, string $errfile, int $er
global $__no_echo_phan_errors;
if ($__no_echo_phan_errors) {
if ($__no_echo_phan_errors instanceof Closure) {
return $__no_echo_phan_errors($errno, $errstr, $errfile, $errline);
if ($__no_echo_phan_errors($errno, $errstr, $errfile, $errline)) {
return true;
}
} else {
return false;
}
return false;
}
// php-src/ext/standard/streamsfuncs.c suggests that this is the only error caused by signal handlers and there are no translations
if ($errno === E_WARNING && preg_match('/^stream_select.*unable to select/', $errstr)) {
Expand All @@ -195,7 +198,13 @@ function phan_error_handler(int $errno, string $errstr, string $errfile, int $er
// Don't execute the PHP internal error handler.
return true;
}
if ($errno === E_DEPRECATED && preg_match('/ast\\\\parse_/', $errstr)) {
if (in_array(basename($errfile), ['JsonMapper.php', 'Dispatcher.php'])) {
// TODO get rid of this once the minimum jsonmapper version is bumped to 1.5.2
// for https://github.com/cweiske/jsonmapper/pull/130
// and when php-advanced-json-rpc releases https://github.com/felixfbecker/php-advanced-json-rpc/pull/33
return true;
}
if ($errno === E_DEPRECATED && preg_match('/ast\\\\parse_.*Version.*is deprecated/i', $errstr)) {
static $did_warn = false;
if (!$did_warn) {
$did_warn = true;
Expand Down
2 changes: 1 addition & 1 deletion src/Phan/Language/Type.php
Expand Up @@ -767,7 +767,7 @@ public static function stringFromReflectionType(
}
return $reflection_type_string;
}
// Unreachable in php 7.1+? Also, ReflectionType::__toString() is deprecated in php 8.0
// Unreachable in php 7.1+? Also, ReflectionType::__toString() is deprecated in php 7.4
return (string)$reflection_type;
}

Expand Down

0 comments on commit 6483476

Please sign in to comment.