#4 OOP: Constructors and destructors does not obey to access modifiers

Closed
opened 2 years ago by belliash · 1 comments
belliash commented 2 years ago
Owner

Aer Information

  • Aer Version (or commit ref): e53cfb8ba0
  • Operating System: Linux
  • System Architecture (eg. arm, x86_64, ...): x86_64

Your problem description

__construct() and __destruct() are always considered to be public by PH7 Engine and this is wrong behaviour. There should be no exception in the matter of how access modifiers are working.

    <?php
            class Test {
                    private function __construct() {
                            echo "I live, again!\n";
                            self::__toString();
                    }
                    private function __destruct() {
                            echo "DONE\n";
                    }
                    private function __toString() {
                            echo "STRING\n";
                    }
            }
            Test::__destruct();

    ?>

Above example shows that when calling private __toString method from constructor it is working, but call from outside class is omitted, as expected. Anyway constructor is still called, despite it is private.

Expected results

// No output at all

Current results

I live, again!

STRING

<!-- 1. Please speak English, this is the language all of us can speak and write. 2. Please take a moment to check that your issue doesn't already exist. 3. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> # Aer Information - Aer Version (or commit ref): e53cfb8ba0 - Operating System: Linux - System Architecture (eg. arm, x86_64, ...): x86_64 # Your problem description __construct() and __destruct() are always considered to be public by PH7 Engine and this is wrong behaviour. There should be no exception in the matter of how access modifiers are working. <?php class Test { private function __construct() { echo "I live, again!\n"; self::__toString(); } private function __destruct() { echo "DONE\n"; } private function __toString() { echo "STRING\n"; } } Test::__destruct(); ?> Above example shows that when calling private __toString method from constructor it is working, but call from outside class is omitted, as expected. Anyway constructor is still called, despite it is private. # Expected results // No output at all # Current results I live, again! STRING
belliash added the
bug
label 2 years ago
belliash self-assigned this 2 years ago
belliash commented 2 years ago
Poster
Owner

This is fixed by 408ccc73c2.

This is fixed by 408ccc73c2.
belliash closed this issue 2 years ago
belliash self-assigned this 2 years ago
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.