Программирование

phpDocumentor.phar не создает каталог: ошибка phar на Windows

Ошибка возникает из‑за неверного разрешения путей с пробелами, когда phpDocumentor пытается записать в phar. Как правильно указать пути и избежать ошибки на Windows.

phpDocumentor.phar fails to generate output: cannot create directory inside phar

Well, I’m running phpDocumentor on Windows using the phpDocumentor.phar file. I execute the following command:

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

The tool scans my source files correctly (the expected number of files is detected), but when it attempts to generate the documentation I receive this error:

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

Environment details

  • Class directory: D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\OfficeTools
  • Output directory: D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\office-tools-doc
  • Location of phpDocumentor.phar: D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\phpDocumentor

Question

Why is phpDocumentor attempting to write to the phpDocumentor.phar/src directory instead of the specified output directory? What am I doing wrong, and how can I resolve this “cannot create directory inside phar” error on Windows?

phpDocumentor is trying to write to a folder inside the PHAR because the
tool mis‑resolves the path to the templates folder when the command is run
from a directory that contains spaces. The short flags (-d / -t) are
accepted, but the argument values are not quoted, so PHP interprets the
space after “Webs” as the end of the path and the rest of the string is
treated as a separate argument. The resolver then constructs a path that
looks inside the PHAR (phar://…/data/templates), and mkdir() fails
because a PHAR archive is read‑only.

Below are the key points that explain why this happens and how to fix it.


Содержание


Почему phpDocumentor использует каталог внутри PHAR?

When phpDocumentor starts, it resolves the location of its built‑in
templates, which are stored inside the PHAR at data/templates. If the
working directory contains spaces and the argument is not quoted, PHP
splits the path at the first space, and the resulting string is
interpreted as a URL to the PHAR itself (phar://…/data/templates).
Since a PHAR is read‑only, any attempt to create a directory inside it
triggers the error you see:

mkdir(): phar error: cannot create directory "phar://…/data/templates"

This behaviour is documented in the PHP manual’s section on PHAR
paths
and has been reported
as a Windows‑specific bug in the phpDocumentor issue tracker
(#1023).


Правильный синтаксис команды

  1. Enclose paths that contain spaces in double quotes.

    bash
    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"
    
  2. Use the long options for clarity.

    bash
    php phpDocumentor.phar run \
        --directory="D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\OfficeTools" \
        --target="D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\office-tools-doc"
    
  3. Run the PHAR from its own directory (or set the working directory
    explicitly) to avoid relative‑path confusion:

    bash
    cd "D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\phpDocumentor"
    php phpDocumentor.phar run -d ..\OfficeTools -t ..\office-tools-doc
    

Решения и обходные пути

Решение Как применить Когда использовать
Параметр --no-templates php phpDocumentor.phar run --no-templates ... Если вам не нужны шаблоны, а только генерация файлов.
Извлечь PHAR phar -x phpDocumentor.pharphp phpDocumentor/src/phpDocumentor/cli.php Позволяет избежать путей внутри PHAR.
Установить PHAR_DIR set PHAR_DIR=D:\Users\Allen\Documents\Websites\My Webs\littlepanda\www\littlepanda\phpDocumentor Позволяет явно указать каталог PHAR.
Запустить с phar.readonly=0 php -d phar.readonly=0 phpDocumentor.phar ... Позволяет писать в PHAR, но это не рекомендуется.

Как извлечь PHAR и запустить из распакованной версии

bash
# Извлечь PHAR
phar -x phpDocumentor.phar

# Перейти в каталог, где находится скрипт
cd phpDocumentor/src/phpDocumentor

# Запустить генерацию
php cli.php run -d "..\..\OfficeTools" -t "..\..\office-tools-doc"

Перенос на phpDocumentor 3

phpDocumentor 2 больше не поддерживается, и многие проблемы с PHAR
устранены в версии 3, которая поставляется через Composer и не
использует архив PHAR. Если вы можете перейти на PHP 8.1+ и Composer,
это самый надёжный способ избежать подобных ошибок.

bash
composer require --dev phpdocumentor/phpdocumentor
vendor/bin/phpdoc run --directory="D:\...\OfficeTools" --target="D:\...\office-tools-doc"

Подробнее о миграции см. в официальной справке
(Migration Guide).


Заключение

  • Ошибка вызвана тем, что phpDocumentor пытается создать каталог внутри PHAR из‑за некорректного разрешения пути, когда в пути есть пробелы.
  • Минимальное исправление: оборачивайте все пути в кавычки и используйте длинные опции (--directory, --target).
  • Если проблема сохраняется, извлеките PHAR и запустите из распакованной версии или перейдите на phpDocumentor 3.
  • После применения одного из решений генерация документации должна пройти без ошибок, и файлы появятся в указанном каталоге вывода.
Авторы
Проверено модерацией
Модерация