網站製作學習誌

記錄學習製作網站的一切

解決 Zend_Tool 在 PHP 5.3 的錯誤

前陣子 pct 用 PHP 5.3 實驗 Zend Framework 1.9.5 的 Zend_Tool 功能時,產生了一堆 Warning 。

因為我一直都是用 PHP 5.2 ,所以沒有出現這個問題。因此趁著假日空閒時間,我特地在 CentOS 上裝了 PHP 5.3 來測試,結果一測馬上就遇到了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# zf
(略)
Warning: include_once(/path-to): failed to open stream: No such file or directory in /path-to/library/Zend/Tool/Framework/Loader/Abstract.php on line 90
  PHP Warning:  include_once(): Failed opening '/path-to' for inclusion (include_path='.:/path-to/library') in /path-to/library/Zend/Tool/Framework/Loader/Abstract.php on line 90
Warning: include_once(): Failed opening '/path-to' for inclusion (include_path='.:/path-to/library') in /path-to/library/Zend/Tool/Framework/Loader/Abstract.php on line 90
  An Error Has Occurred
  An action and provider is required.
Zend Framework Command Line Console Tool v1.9.5
  Usage:
  zf [--global-opts] action-name [--action-opts] provider-name [--provider-opts] [provider parameters ...]
  Note: You may use "?" in any place of the above usage string to ask for more specific help information.
  Example: "zf ? version" will list all available actions for the version provider.
Providers and their actions:
  ProjectProvider
  zf create project-provider name actions
 Profile
  zf show profile
(略)

上網 Google 了一下,找到這篇看不懂語言的討論文,但裡面提供了一段看得懂的程式碼… (XD)

把 /library/Zend/Tool/Framework/Loader/Abstract.php 第 90 行的:

1
include_once $file;

改成:

1
2
3
if (preg_match('/\.php$/', $file)) {
    include_once $file;
}

就可以啦~

這是因為 Zend_Tool 會去掃目錄 (要找尋 Provider 的關係),結果把不是 .php 的 dir 也 include 進來…解法就是判斷該 file 是不是 .php 結尾,不是的話就排除掉~

另外這篇討論文有提到 ZF 1.10 時會修掉這個 Bug 。

Comments