php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70376 Wrong signature for errors in namespaced anonymous functions
Submitted: 2015-08-28 05:37 UTC Modified: 2015-10-13 00:03 UTC
From: me at kelunik dot com Assigned: jpauli (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.0.0RC1 OS:
Private report: No CVE-ID: None
 [2015-08-28 05:37 UTC] me at kelunik dot com
Description:
------------
The namespace shouldn't be repeated after :: and -> for anonymous functions.

https://3v4l.org/F7R3l#v700alpha2

Test script:
---------------
<?php

namespace A {
    class Foo {
        public $foo;
        
        public function __construct() {
            $this->foo = function (int $a) {
                var_dump("foo");
            };
        }
    }
}

namespace {
    ((new A\Foo)->foo)(null);
}

Expected result:
----------------
Fatal error: Uncaught TypeError: Argument 1 passed to A\Foo::{closure}() must be of the type integer, null given, called in /in/F7R3l on line 16 and defined in /in/F7R3l:8
Stack trace:
#0 /in/F7R3l(16): A\Foo->{closure}(NULL)
#1 {main}
  thrown in /in/F7R3l on line 8

Actual result:
--------------
Fatal error: Uncaught TypeError: Argument 1 passed to A\Foo::A\{closure}() must be of the type integer, null given, called in /in/F7R3l on line 16 and defined in /in/F7R3l:8
Stack trace:
#0 /in/F7R3l(16): A\Foo->A\{closure}(NULL)
#1 {main}
  thrown in /in/F7R3l on line 8

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-28 07:29 UTC] bwoebi@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: jpauli
 [2015-08-28 07:29 UTC] bwoebi@php.net
This is a regression introduced by the bug fix for #70159 ... https://github.com/php/php-src/commit/a28115ccdb11301a418cc748ef7716a1687cc585#diff-3a8139128d4026ce0cb0c86beba4e6b9

Thus assigning to Julien.
 [2015-10-13 00:03 UTC] bwoebi@php.net
-Status: Assigned +Status: Not a bug
 [2015-10-13 00:03 UTC] bwoebi@php.net
Actually, thinking about it, it's not quite a bug. The function name is A\{closure} … bound to the Class A\Foo. Hence we end up with A\Foo::A\{closure}.

In case you bindTo() another class, like the class Baz in namespace B, we'll have B\Baz::A\{closure}, still indicating that the Closure is in namespace A.

Hence closing as not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 05 00:01:27 2024 UTC