php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76379 cant touch with $atime=null
Submitted: 2018-05-25 20:50 UTC Modified: 2018-05-26 12:24 UTC
From: remco at priya dot software Assigned: cmb (profile)
Status: Not a bug Package: Filesystem function related
PHP Version: 7.2.6 OS: PHP 7.2.5-1+ubuntu14.04.1+deb.su
Private report: No CVE-ID: None
 [2018-05-25 20:50 UTC] remco at priya dot software
Description:
------------
see the test script

( ! ) Warning: touch(): Utime failed: Operation not permitted in /mnt/c/Library/Server/Vendor/Priya/Module/File/Class/File.class.php on line 40

Test script:
---------------
//works
public static function touch($url='', $time=null, $atime=null){
        if($atime === null){
            return touch($url, $time);
        } else {
            return touch($url, $time, $atime);
        }
    }
// doesnt work:
    public static function touch($url='', $time=null, $atime=null){
        return touch($url, $time, $atime);
    }

//$url = '/mnt/c/Library/Server/Vendor/Priya/Application/Data/Cache/01/1578ee0fedd628ca8227e04bfc7b1e3917fb1833.json' (length=106)
//$time = 1527281173
//$atime = null


( ! ) Warning: touch(): Utime failed: Operation not permitted in /mnt/c/Library/Server/Vendor/Priya/Module/File/Class/File.class.php on line 40

Expected result:
----------------
no warning with the "fix"...
no warning with the "doesn't work"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-26 12:24 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: URL related +Package: Filesystem function related -Assigned To: +Assigned To: cmb
 [2018-05-26 12:24 UTC] cmb@php.net
There is no way to *skip* optional function parameters in PHP.  A
respective RFC[1] had been declined.  Passing NULL to an optional
parameter does *not* necessarily use its default, but NULL, which
in this case is converted to 0.  So it is up to the userland
developer to pass appropriate default values, e.g. in this case:

  function my_touch($url, $time, $atime=null) {
      return touch($url, $time, $atime ?? $time);
  }

[1] <https://wiki.php.net/rfc/skipparams>
 [2018-05-26 12:30 UTC] spam2 at rhsoft dot net
just use strict-mode so that you learn that you can't pass NULL to a int param
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 03:01:23 2020 UTC