關於返回值
「返回已執行程序的終止狀態。如果發生錯誤,則返回 -1。」
以及關於退出狀態的注意事項:「pclose() 內部使用 waitpid(3) 系統呼叫來實作。要取得實際的退出狀態碼,應該使用 pcntl_wexitstatus() 函式。」
關於返回值的說明文件,充其量只是誤導。此函式與 proc_close() 一樣會返回:
* 發生錯誤時返回 -1,
* 如果 WIFEXITED(status) 為真,則返回 WEXITSTATUS(status),或
* 如果 WIFEXITED(status) 為假,則返回 status,
其中 status 是 waitpid() 的狀態參數。
這使得無法區分相對正常的退出或由訊號終止,並將 proc_close 返回值的價值降低為二進位值(正常 / 出現錯誤)。
這可以在 ext/standard/proc_open.c (PHP 5.4.44, 5.6.12) 中的 proc_open_rsrc_dtor() 中看到。
建議使用 pcntl_wexitstatus 的注意事項完全錯誤。因為它已經被使用過,所以無法使用 pcntl_wexitstatus。