ext-php-rs icon indicating copy to clipboard operation
ext-php-rs copied to clipboard

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

Open ju1ius opened this issue 2 years ago • 0 comments

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"
  }
}

ju1ius avatar Nov 10 '22 04:11 ju1ius