Skip to content

Add visability to constructor #541

@Norbytus

Description

@Norbytus

Description

Description

For now all constructor generate as public, and not possibility to declare as private or protected

Use Case

Some time need declare class __construct as private or protected, and instead construct use

public static function new()

or to escape from error You cannot instantiate this class from PHP.

Example

#[php_class]
struct TestClassMethodVisability;

#[php_impl]
impl TestClassMethodVisability {
    #[php(vis = "private")]
    fn __construct() -> Self {
        Self
    }

    #[php(vis = "private")]
    fn private() -> u32 {
        3
    }

    #[php(vis = "protected")]
    fn protected() -> u32 {
        3
    }
}
#[php_class]
struct TestClassProtectedConstruct;

#[php_impl]
impl TestClassProtectedConstruct {
    #[php(vis = "protected")]
    fn __construct() -> Self {
        Self
    }
}
#[php_class]
struct TestClassMethodVisability;

#[php_impl]
impl TestClassMethodVisability {
    #[php(vis = "private")]
    fn __construct() -> Self {
        Self
    }

    #[php(vis = "private")]
    fn private() -> u32 {
        3
    }

    #[php(vis = "protected")]
    fn protected() -> u32 {
        3
    }
}
#[php_class]
struct TestClassProtectedConstruct;

#[php_impl]
impl TestClassProtectedConstruct {
    #[php(vis = "protected")]
    fn __construct() -> Self {
        Self
    }
}

Additional Context

  • I can try implementing this feature myself (please assign me to this issue)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions