php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78776 Abstract method implementation in trait
Submitted: 2019-11-04 07:38 UTC Modified: 2019-11-04 07:55 UTC
From: mozafar dot gholami at gmail dot com Assigned:
Status: Verified Package: Scripting Engine problem
PHP Version: 7.3.11 OS: Win 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mozafar dot gholami at gmail dot com
New email:
PHP Version: OS:

 

 [2019-11-04 07:38 UTC] mozafar dot gholami at gmail dot com
Description:
------------
abstract methods should be implemented by child class and should not be static but when the implementation comes from a trait it cloud be static and code continue running without any problem. 

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

abstract class A
{
    abstract public function createApp();
}

class B extends A
{
    use C;
}

trait C
{
    public static function createApp()
    {
        echo "You should not be here";
    }
}

B::createApp();

Expected result:
----------------
Error for not implementing abstract method


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-04 07:55 UTC] cmb@php.net
-Status: Open +Status: Verified -Package: PHP Language Specification +Package: Scripting Engine problem
 [2019-11-04 07:55 UTC] cmb@php.net
Confirmed: <https://3v4l.org/WgSfr>
 [2019-11-05 13:17 UTC] rowan dot collins at gmail dot com
Specifically, the error when implementing the method directly is:

> Fatal error: Cannot make non static method A::createApp() static in class B

https://3v4l.org/it0Se

The error is displayed correctly if the base method is not abstract: https://3v4l.org/I2E5Y
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Dec 15 00:01:22 2019 UTC