-
-
Notifications
You must be signed in to change notification settings - Fork 149
Open
Labels
Description
The main visibility can be omitted when it is public. Docs
If a property is public, then the main visibility may be omitted. That is, public private(set) and private(set) will have the same result.
So,
class Book
{
public function __construct(
public private(set) string $title,
public protected(set) string $author,
protected private(set) int $pubYear,
public string $bar,
) {}
public function methodThatNowWontParse(): void
{}
}can be shortened to
class Book
{
public function __construct(
private(set) string $title,
protected(set) string $author,
protected private(set) int $pubYear,
public string $bar,
) {}
public function methodThatNowWontParse(): void
{}
}But this triggers an Undefined variable error as given below.
--
The test for this feature contains the following code, which is invalid.
class Book
{
public function __construct(
public private(set) string $title,
public protected(set) string $author,
protected private(get) int $pubYear,
public string $bar,
) {}
public function methodThatNowWontParse(): void
{}
}protected private(get) int $pubYear fails with error
Fatal error: Multiple access type modifiers are not allowed
dantleech, przepompownia and Bleksak