首页 > 解决方案 > 为什么 PHP 类在另一个脚本中运行良好时却在另一个脚本中找不到?

问题描述

我有两个脚本。两个脚本都位于同一服务器上的同一文件夹中。

脚本 1:

<?php

$text = "Is this not working? Why, yes it is.";

$locale = 'en_US';

$i = IntlBreakIterator::createSentenceInstance($locale);
$i->setText($text);

foreach($i->getPartsIterator() as $sentence) {
    echo $sentence . PHP_EOL . '----- next -----' .  PHP_EOL;
}

?>

脚本 2:

... bunch of other code ...

$doc = file_get_contents("file.txt");

$locale = 'en_US';

$i = IntlBreakIterator::createSentenceInstance($locale);
$i->setText($doc);

foreach($i->getPartsIterator() as $sentence) {
    echo $sentence . PHP_EOL . '----- next -----' .  PHP_EOL;
}

... bunch of other code ...

脚本 1 按预期执行,具有所需的输出且没有错误。脚本 2 不执行,PHP 不断抛出错误PHP Fatal error: Uncaught Error: Class 'IntlBreakIterator' not found

这里发生了什么?

标签: php

解决方案


推荐阅读