$ini_path=php_ini_loaded_file()?:'(php.ini path could not be determined - try creating one at '.dirname(PHP_BINARY).'\\php.ini as a new empty file, or one based on php.ini.development or php.ini.production)';
// e.g. https://windows.php.net/downloads/pecl/releases/ast/1.0.16/php_ast-1.0.16-8.0-nts-vs16-x64.zip for php 8.0, 64-bit non thread safe
// e.g. https://windows.php.net/downloads/pecl/releases/ast/1.0.16/php_ast-1.0.16-7.4-ts-vc15-x86.zip for php 7.4, 32-bit thread safe
fprintf(
STDERR,
PHP_EOL."Windows users can download php-ast from https://windows.php.net/downloads/pecl/releases/ast/%s/php_ast-%s-%s-%s-%s-%s.zip".PHP_EOL,
LATEST_KNOWN_PHP_AST_VERSION,
LATEST_KNOWN_PHP_AST_VERSION,
PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION,
PHP_ZTS?'ts':'nts',
PHP_VERSION_ID>=80000?'vs16':'vc15',
PHP_INT_SIZE==4?'x86':'x64'
);
fwrite(STDERR,"(if that link doesn't work, check https://windows.php.net/downloads/pecl/releases/ast/ )".PHP_EOL);
fwrite(STDERR,"To install php-ast, add php_ast.dll from the zip to $extension_dir,".PHP_EOL);
}else{
if(PHP_VERSION_ID<70300){
fwrite(STDERR,"php-ast 1.0.11 is the minimum php-ast version needed for ast version 85. https://pecl.php.net/package/ast/1.0.11/windows does not supply dlls for php 7.2 because php-ast 1.0.11 was published after security support for php 7.2 was dropped".PHP_EOL);
}else{
fprintf(STDERR,"Releases for php %s may not yet be available at https://windows.php.net/downloads/pecl/releases/ast/".PHP_EOL,PHP_VERSION);
}
fwrite(STDERR,"To build php-ast from source for Windows, see https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2 and https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2#building_pecl_extensions".PHP_EOL);
}
fwrite(STDERR,"Then, enable php-ast by adding the following lines to your php.ini file at '$ini_path'".PHP_EOL.PHP_EOL);
1. Unix (PECL): Run 'pecl install ast' and add extension=ast.so to your php.ini.
2. Unix (Compile): Download https://github.com/nikic/php-ast then compile and install the extension as follows:
cd path/to/php-ast
phpize
./configure
make
sudo make install
Additionally, add extension=ast.so to your php.ini file.
EOT
);
}
fwrite(STDERR,"For more information, see https://github.com/phan/phan/wiki/Getting-Started#installing-dependencies".PHP_EOL);
}
// Use the composer autoloader
$found_autoloader=false;
foreach([
dirname(__DIR__,2).'/vendor/autoload.php',// autoloader is in this project (we're in src/Phan and want vendor/autoload.php)
dirname(__DIR__,5).'/vendor/autoload.php',// autoloader is in parent project (we're in vendor/phan/phan/src/Phan/Bootstrap.php and want autoload.php
dirname(__DIR__,4).'/autoload.php',// autoloader is in parent project (we're in non-standard-vendor/phan/phan/src/Phan/Bootstrap.php and want non-standard-vendor/autoload.php
]as$file){
if(file_exists($file)){
require_once($file);
$found_autoloader=true;
break;
}
}
if(extension_loaded('ast')){
// Warn if the php-ast version is too low.
$ast_version=(string)phpversion('ast');
if($ast_version===''){
// Seen in php 7.3 with file_cache when ast is initially enabled but later disabled, due to the result of extension_loaded being assumed to be a constant by opcache.
CLI::printErrorToStderr("extension_loaded('ast') is true, but phpversion('ast') is the empty string. You probably need to clear opcache (opcache.file_cache='".ini_get('opcache.file_cache')."')".PHP_EOL);
}
$phan_output_ast_too_old_and_exit=/** @return never */staticfunction(string$minimum_ast_version,string$php_version_bound)use($ast_version):void{
$error_message=sprintf(
"Phan 5.x requires php-ast %s+ to properly analyze ASTs for php %s+. php-ast %s and php %s is installed.".PHP_EOL,
$minimum_ast_version,
$php_version_bound,
$ast_version,
PHP_VERSION
);
CLI::printErrorToStderr($error_message);
phan_output_ast_installation_instructions();
fwrite(STDERR,"Exiting without analyzing files.".PHP_EOL);
"WARNING: Phan 5.x requires php-ast 1.0.2+ to properly analyze ASTs for php 7.4+ (1.0.15+ is recommended). php-ast %s and php %s is installed.".PHP_EOL,
// Warn for 8.3.0RC1, 8.0.0RC1, 7.4.0alpha1, 7.3.0-dev, etc.
// But don't warn for 8.4.0 since there's no way yet to upgrade to a stable release.
fwrite(STDERR,"WARNING: Phan may not work properly in versions prior to the first stable release of a php minor version. The currently used PHP version is ".PHP_VERSION.PHP_EOL);
}
unset($ast_version);
}
unset($file);
if(!$found_autoloader){
fwrite(STDERR,"Could not locate the autoloader\n");
}
unset($found_autoloader);
define('EXIT_SUCCESS',0);
define('EXIT_FAILURE',1);
define('EXIT_ISSUES_FOUND',EXIT_FAILURE);
// Note that Phan's source code now throws exceptions rather than using assert(),
// but make the settings consistent for any third party plugins still using assert().
// assert_options has been deprecated starting with PHP 8.3 so use ini_set instead.
// See https://wiki.php.net/rfc/assert-string-eval-cleanup#formal_proposal
// Use ini_set where the value Phan uses is the same as php's defaults.
fwrite(STDERR,"WARNING: Using a limited polyfill for filter_var() instead of the real filter_var(). **ANALYSIS RESULTS MAY DIFFER AND PLUGINS MAY HAVE ISSUES.** Install and/or enable https://www.php.net/filter to fix this. PHAN_DISABLE_FILTER_VAR_POLYFILL=1 can be used to disable this polyfill.\n");
require_once__DIR__.'/filter_var.php_polyfill';
}
}
/**
* Print more of the backtrace than is done by default
fwrite(STDERR,"(Some long strings (usually JSON of AST Nodes) were truncated. To print more details for some stack frames of this uncaught exception,".
"increase the Phan config setting debug_max_frame_length)".PHP_EOL);
}
exit(EXIT_FAILURE);
});
/**
* Executes $closure with Phan's default error handler disabled.
*
* This is useful in cases where PHP notices are unavoidable,
* e.g. notices in preg_match() when checking if a regex is valid
* and you don't want the default behavior of terminating the program.
fwrite(STDERR,"(Some long strings (usually JSON of AST Nodes) were truncated. To print more details for some stack frames of this ".($is_crash?"crash":"log").", ".
"increase the Phan config setting debug_max_frame_length)".PHP_EOL);
}
}
}
/**
* The error handler for PHP notices, etc.
* This is a named function instead of a closure to make stack traces easier to read.