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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
16 + 25 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 05:01:28 2024 UTC