Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with MkdirTask #1619

Closed
jawira opened this issue Jul 27, 2021 · 2 comments · Fixed by #1629
Closed

Error with MkdirTask #1619

jawira opened this issue Jul 27, 2021 · 2 comments · Fixed by #1629
Assignees
Milestone

Comments

@jawira
Copy link
Contributor

jawira commented Jul 27, 2021

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

siad007 added a commit to siad007/phing that referenced this issue Aug 22, 2021
siad007 added a commit that referenced this issue Aug 22, 2021
@siad007
Copy link
Member

siad007 commented Aug 22, 2021

@jawira solved 🙇🏼

@siad007 siad007 added this to the 3.0.0-RC3 milestone Aug 22, 2021
mpdude added a commit to webfactory/phing that referenced this issue Jan 13, 2022
... in Anlehnung an phingofficial#1629.

Das Problem ist, dass wir keinen Error Handler verwenden, der Errors in Exceptions umwandelt.

Daher der eigene Handler, der den Fehler endgültig still unterschlägt.

Hintergrund: https://php.watch/versions/8.0/fatal-error-suppression
@MaximilianKresse
Copy link
Contributor

The error still exists in the current main branch.

It looks like the problem is in your error handler. The error handler doesn't handle the silent operator @ correctly: https://github.com/phingofficial/phing/blob/main/src/Phing/Phing.php#L1059

With PHP 8.0 there were a change to the behavior.
Impact on Error Handlers is important for you.

TLDR: Change the (error_reporting() > 0) with something like:

if (!(\error_reporting() & $level)) {
  return true;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants