Skip to content

[Intl] do not access typed property before initialization #58623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,18 @@ public function testReverse()
$this->expectException(\IntlException::class);
EmojiTransliterator::create('emoji-en', EmojiTransliterator::REVERSE);
}

public function testGetErrorCodeWithUninitializedTransliterator()
{
$transliterator = EmojiTransliterator::create('emoji-en');

$this->assertSame(0, $transliterator->getErrorCode());
}

public function testGetErrorMessageWithUninitializedTransliterator()
{
$transliterator = EmojiTransliterator::create('emoji-en');

$this->assertFalse($transliterator->getErrorMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public function createInverse(): self

public function getErrorCode(): int|false
{
return $this->transliterator?->getErrorCode() ?? 0;
return isset($this->transliterator) ? $this->transliterator->getErrorCode() : 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed? Do the tests fail without the patch? Doesn't the ?? already guard against these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null-coalesce operator doesn't help here when calling a method (that's why this went unnoticed in the linked discussion). The tests are failing without these changes (see also https://3v4l.org/HBV0b).

}

public function getErrorMessage(): string|false
{
return $this->transliterator?->getErrorMessage() ?? false;
return isset($this->transliterator) ? $this->transliterator->getErrorMessage() : false;
}

public static function listIDs(): array
Expand Down