Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Idea: disallow protected members in final classes

Open
#57 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
tooling

Research direction

Review the originating Slevomat issue and the PHPStan strict-rules project to locate the existing rule entry point and related tests. Implement the check for new protected members in final classes while allowing inherited protected methods that are overridden, then verify the reported examples and corresponding rule tests.

Written by the indexing model from the issue text.

Description

Originally reported as https://github.com/slevomat/coding-standard/issues/563 but impossible to implement there.

The idea is to ensure that final classes don't contain any new protected members. Such members can be made private because there are no descendants that can use them. Special care has to be taken to avoid changing protected methods from parent classes to private, such as in this example:

abstract class MyAbstractClass
{
    protected function protectedFunction()
    {
        echo 'foo';
    }
}

final class MyClass extends MyAbstractClass
{
    protected function protectedFunction()
    {
        echo 'bar';
    }
}

In this case, protectedFunction may not cause an error because its visibility can't be changed to private.

Dominant language
PHP
Stars
711
Forks
62
Avg merge
35m
Merged PRs (30d)
4

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpstan/phpstan-strict-rules

All issues in phpstan/phpstan-strict-rules

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.