1.2.823. No Private Abstract Method In Trait

Method could not be both abstract and private in traits. This was changed in PHP 8.0 : the class might overwrite the trait’s method, since it has precedence of it. And when the class doesn’t overwrite it, then the class has an abstract method, and can’t be instantiated.

This might be important for backward incompatibility, although it doesn’t lint in previous versions.

<?php

 trait t { abstract private function foo() ;}

 class x {
    use t;

    // valid
    private function foo() {}
}

// This is a hidden abstract class
class y {
    use t;
}


?>

See also Abstract Trait Members.

1.2.823.1. Specs

Short name

Traits/NoPrivateAbstract

Rulesets

All, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56, CompatibilityPHP70, CompatibilityPHP71, CompatibilityPHP72, CompatibilityPHP73, CompatibilityPHP74

Exakat since

2.4.5

PHP Version

With PHP 8.0 and more recent

Severity

Minor

Time To Fix

Quick (30 mins)

Changed Behavior

PHP 8.0 - More

Precision

Very high

Features

trait, abstract

Available in

Entreprise Edition, Exakat Cloud