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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: si dot schubert at live dot de
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Sun Dec 22 11:01:30 2024 UTC