php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79824 Use late binding scope instead of scope in stack trace
Submitted: 2020-07-09 19:15 UTC Modified: 2020-07-19 12:03 UTC
From: si dot schubert at live dot de Assigned:
Status: Open Package: *General Issues
PHP Version: 8.0.0alpha2 OS: Debian GNU/Linux 10 (buster)
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-07-09 19:15 UTC] si dot schubert at live dot de
Description:
------------
the message and stack trace references the wrong class

Test script:
---------------
class A
{
    public static function new(): static
    {
        return new self();
    }
}

class B extends A
{
}

B::new();


Expected result:
----------------
Fatal error: Uncaught TypeError: B::new(): Return value must be of type B, A returned in /app/bin/runner:8
Stack trace:
#0 /app/bin/runner(16): B::new()
#1 {main}
  thrown in /app/bin/runner on line 8

Actual result:
--------------
Fatal error: Uncaught TypeError: A::new(): Return value must be of type B, A returned in /app/bin/runner:8
Stack trace:
#0 /app/bin/runner(16): A::new()
#1 {main}
  thrown in /app/bin/runner on line 8

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-10 12:11 UTC] nikic@php.net
-Summary: static return type: message and stacktrace wrong for Uncaught TypeError +Summary: Use late binding scope instead of scope in stack trace -Type: Bug +Type: Feature/Change Request
 [2020-07-10 12:11 UTC] nikic@php.net
This has no relation to the static return type. I'm also not convinced showing the LSB scope instead of the scope makes sense.
 [2020-07-19 12:03 UTC] si dot schubert at live dot de
thanks for checking. If it is not a bug, feel free to close it. From a userland perspective it felt weird to get A::new() when actually calling B::new(). But this is maybe also caused by the fact, that I do not fully understand how objects are built in PHP. Is there an instance A(i) when creating B(i)? I always assumed, that there is just B(i) build from B (plus A where needed).
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Oct 30 17:01:24 2020 UTC