You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下phpDocumentor.phar生成文档失败:无法创建phar内目录

phpDocumentor.phar在Windows下生成文档报错问题

操作详情

在Windows系统中执行phpDocumentor文档生成命令:

php phpDocumentor.phar run -d [class directory] -t [output directory]

程序可正常扫描文件,但生成输出时触发报错:

Impossible to create the root directory "phar://D:/Users/Allen/Documents/We
  bsites/My%20Webs/littlepanda/www/littlepanda/phpDocumentor/phpDocumentor.ph
  ar/src/phpDocumentor/../../data/templates". mkdir(): phar error: cannot cre
  ate directory "phar://D:/Users/Allen/Documents/Websites/My%20Webs/littlepan
  da/www/littlepanda/phpDocumentor/phpDocumentor.phar/src/phpDocumentor/../..
  /data/templates", no phar archive specified

相关路径

  • 类目录:
D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\OfficeTools
  • 输出目录:
D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\office-tools-doc
  • phpDocumentor.phar存放路径:
D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\phpDocumentor

疑问

操作存在什么问题?为何phpDocumentor尝试写入phpDocumentor.phar/src目录而非指定输出目录?


问题分析与解决方案

核心原因

  1. 含空格路径未加引号导致解析错误:你的路径中存在My Webs这类带空格的目录,执行命令时未用引号包裹路径,导致命令行将空格后的内容当作新参数,phpDocumentor无法正确识别输出目录,进而触发内部模板目录的错误写入逻辑。
  2. Phar包的只读属性限制:Phar归档文件默认是只读的,phpDocumentor尝试写入Phar包内部的data/templates目录本身就违反权限规则,这是路径解析错误引发的次生问题。

解决步骤

  1. 给含空格的路径添加双引号:执行命令时,将类目录和输出目录用双引号包裹,确保路径被完整解析:
php phpDocumentor.phar run -d "D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\OfficeTools" -t "D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\office-tools-doc"
  1. 切换到Phar文件所在目录执行:先进入phpDocumentor.phar的存放目录,再用相对路径执行命令,避免路径解析混乱:
cd D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\phpDocumentor
php phpDocumentor.phar run -d "../OfficeTools" -t "../office-tools-doc"
  1. 验证Phar扩展配置:确保PHP配置文件php.ini中phar.readonly设置为Off(此配置主要避免后续潜在的Phar写入问题,当前报错核心是路径解析),修改后重启PHP环境。

内容的提问来源于stack exchange,提问作者Allen Yu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 22:46:00