我的一个脚本需要PEAR来获得一些额外的功能.我需要一种方法可以检测PEAR本身是否安装了PEAR.因为PEAR.php如果正确安装将在include路径中,我想我可以检查PEAR.phpwith 的存在,file_exists()然后检查其中的PEAR类,以尝试确定它是否实际上是我想要的文件.但是听起来非常糟糕且不可靠.
任何人都可以提出更好或更好的方法吗?
小智 8
您可以尝试使用以下设置,而不是使用file_exists:
$filePath = stream_resolve_include_path('System.php');
if ($filePath !== false)
{
require_once('System.php'); // you could use $filePath as well
echo 'PEAR installed';
}
else
{
echo 'PEAR not installed';
}
Run Code Online (Sandbox Code Playgroud)
棘手的部分是,PEAR很可能被添加到当前的包含路径中.这就是你可以使用System.php而不是/path/to/pear/System.php的原因.通过这种方式,您可以确定是否已安装PEAR.