Skip to content

Error with MkdirTask #1619

@jawira

Description

@jawira

Describe the bug

MkdirTask displays errors when creating nested directories in PHP 8.

Steps To Reproduce

You can reproduce the problem with the following buildfile:

<?xml version="1.0" encoding="UTF-8"?>
<project name="demo" default="create-dirs">

    <target name="create-dirs">
        <delete dir="foo"/>
        <mkdir dir="foo/bar/baz"/>
    </target>

</project>

Execute the target using PHP 8:

$ /usr/bin/php8.0 /usr/local/bin/phing create-dirs
Buildfile: /home/jawira/PhpstormProjects/deleteme/build.xml

demo > create-dirs:

   [delete] Deleting directory /home/jawira/PhpstormProjects/deleteme/foo
[PHP Error] mkdir(): No such file or directory [line 398 of phar:///usr/local/bin/phing/src/Phing/Io/FileSystem.php]
[PHP Error] mkdir(): No such file or directory [line 398 of phar:///usr/local/bin/phing/src/Phing/Io/FileSystem.php]
    [mkdir] Created dir: /home/jawira/PhpstormProjects/deleteme/foo/bar/baz

BUILD FINISHED

Total time: 0.1032 seconds

Expected behavior

Execute create-dirs with PHP 7.4 in order to see the expected behaviour:

$ /usr/bin/php7.4 /usr/local/bin/phing create-dirs
Buildfile: /home/jawira/PhpstormProjects/deleteme/build.xml

demo > create-dirs:

   [delete] Deleting directory /home/jawira/PhpstormProjects/deleteme/foo
    [mkdir] Created dir: /home/jawira/PhpstormProjects/deleteme/foo/bar/baz

BUILD FINISHED

Total time: 0.1020 seconds

As you can see in the output, there's no [PHP Error].

Additional context

The error occurs in the line:

$return = @mkdir($f->getAbsolutePath());

The problem is the @ error suppression operator. In PHP 8 this operator has been modified, some errors are not silenced anymore.

Source: https://php.watch/versions/8.0/fatal-error-suppression

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions