Skip to content

Don't expose accessor methods when using getter/setter macros #176

@ju1ius

Description

@ju1ius

When using the getter/setter macros, the property is created, but the accessor methods are exposed to php.
Also, the generated property is not exposed to the Reflection API.

#[php_class]
pub struct Test(u64);

#[php_impl]
impl Test {
  pub fn __construct(field: u64) { Self(field) }
  #[getter]
  pub fn get_field() -> u64 { self.0 }
}
<?php
$test = new Test(42);
var_dump($test->field);
$rc = new ReflectionClass($test);
var_dump($rc);
var_dump($rc->getMethods());

Expected result:

int(42)
array(1) {
  [0] =>
  class ReflectionProperty#4 (2) {
    public string $name =>
    string(8) "field"
    public string $class =>
    string(7) "Test"
  }
}
array(1) {
  [0] =>
  class ReflectionMethod#5 (2) {
    public string $name =>
    string(11) "__construct"
    public string $class =>
    string(3) "Test"
  }
}

Actual result:

int(42)
array(0) {
}
array(2) {
  [0] =>
  class ReflectionMethod#3 (2) {
    public string $name =>
    string(6) "getField"
    public string $class =>
    string(3) "Foo"
  }
  [1] =>
  class ReflectionMethod#5 (2) {
    public string $name =>
    string(11) "__construct"
    public string $class =>
    string(3) "Test"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions